Skip to content
This repository has been archived by the owner on Jun 26, 2018. It is now read-only.

Catch and handle errors in pattern lab builds #821

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

isaacchansky
Copy link
Contributor

@isaacchansky isaacchansky commented May 9, 2018

Description

When pattern lab builds break, error messages were being suppressed. This should surface them again.

Related Issue / Ticket

Steps to Test

  1. add some malformed twig code to a twig file
  2. run gulp
  3. See the verbose error in the console

Screenshots

Use something like licecap to capture gifs to demonstrate behaviors.

Additional Notes:

Anything else to add?

Impacted Areas in Application

@todo

Today I learned...

@isaacchansky isaacchansky requested a review from rbayliss May 9, 2018 13:10
@rbayliss
Copy link
Contributor

Hey @isaacchansky, I checked this out and I'm not sure I understand what you're requesting. On the dev branch, If I run gulp and wait for the initial build to complete, then enter some invalid Twig into a template, I see the following errors in my console:
screen shot 2018-05-21 at 10 18 01 am

So it looks like the current state (on the dev branch) is that it's telling us when there's a fatal syntax error, although it does suppress the output of those non-fatal warnings until we hit a fatal error. Am I missing something?

@isaacchansky
Copy link
Contributor Author

Interesting. So, on my machine if I add an unclosed IF statement to a twig file, I get the following on dev:

Browsersync] Reloading Browsers...
[22:21:53] Starting 'patternlab:build'...
[22:21:53] Starting 'patternlab:patterns'...
[22:21:55] 'patternlab:patterns' errored after 1.65 s
[22:21:55] Error: Command failed: php '/Users/isaacchansky/Clients/MassGov/mayflower/styleguide/core/console' --generate --patternsonly
 `php '/Users/isaacchansky/Clients/MassGov/mayflower/styleguide/core/console' --generate --patternsonly` (exited with error code 255)
    at callback (/Users/isaacchansky/Clients/MassGov/mayflower/styleguide/node_modules/child-process-promise/lib/index.js:33:27)
    at ChildProcess.exithandler (child_process.js:212:5)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:194:7)
    at maybeClose (internal/child_process.js:899:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
[22:21:55] 'patternlab:build' errored after 1.65 s

And then on this branch for the PR I get:


Fatal error: Uncaught Twig_Error_Syntax: Unexpected end of template in "@atoms/decorative-link.twig" at line 9. in /Users/isaacchansky/Clients/MassGov/mayflower/styleguide/vendor/twig/twig/lib/Twig/TokenStream.php:59
Stack trace:
#0 /Users/isaacchansky/Clients/MassGov/mayflower/styleguide/vendor/twig/twig/lib/Twig/TokenParser/If.php(40): Twig_TokenStream->next()
#1 /Users/isaacchansky/Clients/MassGov/mayflower/styleguide/vendor/twig/twig/lib/Twig/Parser.php(187): Twig_TokenParser_If->parse(Object(Twig_Token))
#2 /Users/isaacchansky/Clients/MassGov/mayflower/styleguide/vendor/twig/twig/lib/Twig/Parser.php(100): Twig_Parser->subparse(NULL, false)
#3 /Users/isaacchansky/Clients/MassGov/mayflower/styleguide/vendor/twig/twig/lib/Twig/Environment.php(619): Twig_Parser->parse(Object(Twig_TokenStream))
#4 /Users/isaacchansky/Clients/MassGov/mayflower/styleguide/vendor/twig/twig/lib/Twig/Environment.php(671): Twig_Environment->parse(Object(Twig_TokenStream))
#5 /Users/isaacchansky/Clients/MassGov/mayflower/styleguide/vendor/twig/t in /Users/isaacchansky/Clients/MassGov/mayflower/styleguide/vendor/twig/twig/lib/Twig/TokenStream.php on line 59

So, the goal was to surface line numbers with errors in twig templates.

Likewise for JSON files, on dev if I have an unquoted attribute I get:

[22:26:20] Error: Command failed: php '/Users/isaacchansky/Clients/MassGov/mayflower/styleguide/core/console' --generate --patternsonly
 `php '/Users/isaacchansky/Clients/MassGov/mayflower/styleguide/core/console' --generate --patternsonly` (exited with error code 1)
    at callback (/Users/isaacchansky/Clients/MassGov/mayflower/styleguide/node_modules/child-process-promise/lib/index.js:33:27)
    at ChildProcess.exithandler (child_process.js:212:5)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:194:7)
    at maybeClose (internal/child_process.js:899:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
[22:26:20] 'patternlab:build' errored after 535 ms

But on this branch for the PR I get:


The JSON file, decorative-link.json, wasn't loaded. The error: Syntax error, malformed JSON

Parse error on line 1:

^

(note: it always says line 1 due to what I assume is a lack of expansion on parsing, but you still get the file name).

@isaacchansky
Copy link
Contributor Author

In case this is a machine setup difference:

$ node -v
v7.8.0

$ npm -v
4.2.0

$ gulp -v
[22:27:20] CLI version 2.0.1
[22:27:20] Local version 4.0.0

$ php -v
PHP 7.1.16 (cli) (built: Apr  1 2018 13:14:42) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants