Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sass errors stop Gulp to make them clearer #977

Closed
wants to merge 1 commit into from

Conversation

joelanman
Copy link
Contributor

@joelanman joelanman commented Jan 8, 2021

attempt to fix #295

on a sass error, the Prototype Kit now exits (no prototype will appear in the browser)

please note there are 2 other approaches discussed in the comments below

it would be nice to clean up the error, I think we just need messageFormatted, it currently looks like this:

screenshot: sass error written to terminal and the kit exits

@joelanman
Copy link
Contributor Author

slightly odd, when I force this error:

.test{
    background: url(
}

I get a segmentation fault from Gulp, which seems a bit wrong

Segmentation fault: 11

@joelanman
Copy link
Contributor Author

joelanman commented Jan 8, 2021

Approach 2

tried a slightly different approach and it outputs this which I think is slightly better? Would prefer without the stack trace

code:

    .pipe(sass({ outputStyle: 'expanded' }).on('error', function (error) {
      done(new Error(error.message))
    }))

output:

[18:30:37] Finished 'copy-assets-documentation' after 294 ms
[18:30:37] 'sass' errored after 591 ms
[18:30:37] Error: app/assets/sass/application.scss
Error: no mixin named missing-mixin
        on line 22 of app/assets/sass/application.scss
        from line 3 of app/assets/sass/application-ie8.scss
>>     @include missing-mixin;

   -------------^

    at DestroyableTransform.<anonymous> (/Users/joelanman/projects/govuk-prototype-kit/gulp/sass.js:28:12)
    at DestroyableTransform.emit (events.js:215:7)
    at DestroyableTransform.EventEmitter.emit (domain.js:475:20)
    at onwriteError (/Users/joelanman/projects/govuk-prototype-kit/node_modules/readable-stream/lib/_stream_writable.js:449:12)
    at onwrite (/Users/joelanman/projects/govuk-prototype-kit/node_modules/readable-stream/lib/_stream_writable.js:470:11)
    at WritableState.onwrite (/Users/joelanman/projects/govuk-prototype-kit/node_modules/readable-stream/lib/_stream_writable.js:180:5)
    at DestroyableTransform.afterTransform (/Users/joelanman/projects/govuk-prototype-kit/node_modules/readable-stream/lib/_stream_transform.js:93:3)
    at errorM (/Users/joelanman/projects/govuk-prototype-kit/node_modules/gulp-sass/index.js:122:12)
    at Object.callback (/Users/joelanman/projects/govuk-prototype-kit/node_modules/gulp-sass/index.js:131:16)
    at options.error (/Users/joelanman/projects/govuk-prototype-kit/node_modules/node-sass/lib/index.js:294:32)
[18:30:37] 'generate-assets' errored after 643 ms
[18:30:37] 'default' errored after 645 ms
Segmentation fault: 11

@joelanman
Copy link
Contributor Author

joelanman commented Jan 8, 2021

Approach 3

forcing process.exit in the error handler gives this, which is the cleanest so far, but also includes an unhelpful suggestion from gulp

code:

    .pipe(sass({ outputStyle: 'expanded' }).on('error', function (error) {
      console.error(error.message)
      process.exit(1)
    }))

output:

[18:36:28] Finished 'copy-assets-documentation' after 239 ms
app/assets/sass/application.scss
Error: no mixin named missing-mixin
        on line 22 of app/assets/sass/application.scss
        from line 3 of app/assets/sass/application-ie8.scss
>>     @include missing-mixin;

   -------------^

[18:36:29] The following tasks did not complete: default, generate-assets, <parallel>, sass, sass-documentation
[18:36:29] Did you forget to signal async completion?
Segmentation fault: 11

@joelanman
Copy link
Contributor Author

Gulp has an open issue to document how to handle errors, but it's 6 years old now

gulpjs/gulp#359

@joelanman joelanman added this to Needs review in Design System Sprint Board Jan 11, 2021
@kellylee-gds kellylee-gds moved this from Needs review to Blocked in Design System Sprint Board Jan 26, 2021
@trang-erskine trang-erskine added the 🕔 Hours A well understood issue which we expect to take less than a day to resolve. label Feb 1, 2021
@trang-erskine trang-erskine moved this from Blocked ⛔ to In progress 📝 in Design System Sprint Board Feb 1, 2021
@36degrees 36degrees self-requested a review February 1, 2021 15:23
@trang-erskine trang-erskine moved this from In progress 📝 to Needs review 🔍 in Design System Sprint Board Feb 1, 2021
@36degrees 36degrees removed this from Needs review 🔍 in Design System Sprint Board Feb 1, 2021
@joelanman
Copy link
Contributor Author

we discussed this on the team - concerned that a total exit might be annoying for users - they would have to fix the sass and restart the kit. Going to investigate options where users only have to fix the sass.

@joelanman joelanman added this to Needs review 🔍 in Design System Sprint Board via automation Feb 3, 2021
@joelanman joelanman moved this from Needs review 🔍 to In progress 📝 in Design System Sprint Board Feb 3, 2021
@kellylee-gds kellylee-gds removed this from In progress 📝 in Design System Sprint Board Feb 19, 2021
@joelanman joelanman marked this pull request as draft February 22, 2021 15:12
@joelanman
Copy link
Contributor Author

I tried deleting the css before trying the compile. This fails, leaving no css. BrowserSync tries to load the new css and fails, however this does not make any difference to the loaded page. Refreshing the page manually does show a broken page as expected

screenshot of browser with page that looks correct but the css file is missing

@36degrees
Copy link
Member

Closing in favour of #990

@36degrees 36degrees closed this Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🕔 Hours A well understood issue which we expect to take less than a day to resolve.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make sass compilation errors more obvious
4 participants