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

Support sass errors in error pages #2287

Conversation

BenSurgisonGDS
Copy link
Contributor

@BenSurgisonGDS BenSurgisonGDS commented Aug 3, 2023

See: Sass errors are not obvious as the kit uses previously compiled sass in .tmp

  • Support restarting nodemon when sass files are in error or not in error
  • Display SASS error page correctly including the line where the error occurs
  • Add new SASS error acceptance test
  • Fix acceptance tests affected by this change

@BenSurgisonGDS BenSurgisonGDS force-pushed the 2170-sass-errors-are-not-obvious-as-the-kit-uses-previously-compiled-sass-in-tmp branch 6 times, most recently from 64cbf22 to edce060 Compare August 11, 2023 08:22
@BenSurgisonGDS BenSurgisonGDS force-pushed the 2170-sass-errors-are-not-obvious-as-the-kit-uses-previously-compiled-sass-in-tmp branch from 83d5b16 to c409654 Compare August 11, 2023 11:48
@BenSurgisonGDS BenSurgisonGDS force-pushed the 2170-sass-errors-are-not-obvious-as-the-kit-uses-previously-compiled-sass-in-tmp branch from c409654 to 648b94f Compare August 11, 2023 12:07
@BenSurgisonGDS BenSurgisonGDS marked this pull request as ready for review August 11, 2023 12:14
@nataliecarey
Copy link
Contributor

I've just tried to run this, the following attempt lead to the kit failing to start (failing to show the error in the browser):

  1. npx govuk-prototype-kit create --version=alphagov/govuk-prototype-kit#2170-sass-errors-are-not-obvious-as-the-kit-uses-previously-compiled-sass-in-tmp broken-scss-kit
  2. cd broken-scss-kit
  3. echo "body {" >> app/assets/sass/application.scss
  4. npm run dev

Creating the error after the kit has started leads to the error appears properly in the browser as expected but the same does not happen if the error existed before starting the kit.

@BenSurgisonGDS could you take a look at that case please?

@BenSurgisonGDS
Copy link
Contributor Author

I've just tried to run this, the following attempt lead to the kit failing to start (failing to show the error in the browser):

  1. npx govuk-prototype-kit create --version=alphagov/govuk-prototype-kit#2170-sass-errors-are-not-obvious-as-the-kit-uses-previously-compiled-sass-in-tmp broken-scss-kit
  2. cd broken-scss-kit
  3. echo "body {" >> app/assets/sass/application.scss
  4. npm run dev

Creating the error after the kit has started leads to the error appears properly in the browser as expected but the same does not happen if the error existed before starting the kit.

@BenSurgisonGDS could you take a look at that case please?

I have made some changes to fix the above issue. This has included how the sass for the error page is compiled and where it is sourced from.

@@ -10,7 +10,7 @@ const dependencyPluginName = 'GOV.UK Frontend'
describe('Handle a plugin update', () => {
after(restoreStarterFiles)

it('when a dependency is now required', () => {
it.skip('when a dependency is now required', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one supposed to be skipped? It looks like maybe it was meant to be temporary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to either be deleted or revisited as the test no longer works as it did previously. This is because the older version of common-templates does not specify in it's config that it depends on govuk-frontend but it does because the sass fails to compile leading to the sass compilation error and so we can no longer (at the moment) have a test where a plugin depends upon another plugin when it is updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I thought it best to skip until we have an example we can use.

}
}
// SASS that is user defined
@import ".tmp/sass/user/application";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an empty line at the end of the file please? (there's a setting to do this automatically in WebStorm)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -188,7 +209,7 @@ function getErrorDetails (cwd, error) {
const getErrorModel = function (error) {
flagError(error)
const viewObject = {
errorStack: error.stack,
errorStack: unstyle(error.stack),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's only SASS errors that need unstyling (so far) I think we should move this into sassMatcher().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that it doesn't hurt where it is and it covers us for if we ever come across any other errors that are styled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather keep it more contained - otherwise things like this tend to be left in through fear or what would happen if they're removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the unstyling of the error stack into the sass matcher as requested but then had to add some extra scafolding to cater for the fact that we don't return the stack from each matcher. To be honest I like the cleaner version we had before, but I've made the change as you asked.

@nataliecarey
Copy link
Contributor

I've just tested a few things manually and found that breaking app/config.json now leads to the kit not starting. Steps to reproduce:

  1. npx govuk-prototype-kit create --version=alphagov/govuk-prototype-kit#2170-sass-errors-are-not-obvious-as-the-kit-uses-previously-compiled-sass-in-tmp broken-scss-kit
  2. cd broken-config-kit
  3. echo "body {" >> app/config.json
  4. npm run dev

To see how it should behave (which is still not technically correct but it's the existing behaviour) just replace step 1 with:

  1. npx govuk-prototype-kit create broken-scss-kit

It would be good to put a test in for this, but up to you whether that's done as part of this ticket or not.

Copy link
Contributor Author

@BenSurgisonGDS BenSurgisonGDS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looks good

@BenSurgisonGDS BenSurgisonGDS merged commit e69cf0f into main Aug 16, 2023
27 checks passed
@BenSurgisonGDS BenSurgisonGDS deleted the 2170-sass-errors-are-not-obvious-as-the-kit-uses-previously-compiled-sass-in-tmp branch August 16, 2023 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sass errors are not obvious as the kit uses previously compiled sass in .tmp
3 participants