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

config(): Add safety falback for when running in production #11686

Merged
merged 2 commits into from
Mar 3, 2017

Conversation

dmsnell
Copy link
Member

@dmsnell dmsnell commented Mar 1, 2017

Recently the data layer experienced a total failure when #11490 merged
in and crashed when it failed to initialize the new middleware handler.

The fact that a key was requested for which no value existed led to
config() raising an Error which causes the entire middleware chain
to fail to build.

Now config() has been modified to only raise an actual Error when
the NODE_ENV=developement and instead in all other environments to
simply log a message to the browser console and return undefined. This
should allow us to still catch any mistakes by the obvious message while
preventing such otherwise-small errors from cascading out-of-control.

Testing
Since no specific changes were made to app code a smoke-test and test-run should suffice to validate these changes. config() is generated at build time so make sure to at least make build before testing. There are new unit tests to confirm the behavior but this should get a manual confirmation as well.

Console message for non-development environments
screen shot 2017-03-01 at 9 06 14 pm

😄

@dmsnell dmsnell added Framework [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Mar 1, 2017
@dmsnell dmsnell requested review from blowery, ockham, gwwar and aduth March 1, 2017 20:28
@matticbot
Copy link
Contributor

@matticbot matticbot added the [Size] M Medium sized issue label Mar 1, 2017
* to crash execution early. However, because many modules
* call this function in the module-global scope a failure
* here can not only crash that module but also entire
* subsystems within Calypso. Therefore if the NODE_ENV is
Copy link
Contributor

Choose a reason for hiding this comment

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

what does subsystem mean? Are there any subsystems other than the data-layer?

Copy link
Member Author

Choose a reason for hiding this comment

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

the entire redux tree, sections, libs

can you think of a clearer description? I'm open to edits

Copy link
Contributor

Choose a reason for hiding this comment

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

What if we simplify it a bit?

However, because many modules call this function in the module-global scope early in execution, this will likely break main application flows or cause unexpected behavior to occur.

Copy link
Member Author

@dmsnell dmsnell Mar 2, 2017

Choose a reason for hiding this comment

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

Updated wording in 3f64db7 (and rebased to squash)

samouri
samouri previously requested changes Mar 1, 2017
Copy link
Contributor

@samouri samouri left a comment

Choose a reason for hiding this comment

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

great tests!
I love this change.

The config you've changed won't help much though. What we need to change is the one spit out by regenerate-client

@samouri samouri dismissed their stale review March 1, 2017 21:12

I was wrong, config is actually imported within regenerate-client and its functions are toStringed

@dmsnell
Copy link
Member Author

dmsnell commented Mar 1, 2017

The config you've changed won't help much though. What we need to change is the one spit out by regenerate-client

I think that this is an incorrect statement. I believe that I have changed the one that needs to be updated.

@samouri
Copy link
Contributor

samouri commented Mar 1, 2017

Code + Behavior LGTM

// display console error only in a browser
// (not in tests, for example)
if ( 'undefined' !== typeof window ) {
console.error( errorMessage );
Copy link
Contributor

@aduth aduth Mar 1, 2017

Choose a reason for hiding this comment

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

Wouldn't the above thrown error log to console? Or, if not, would it be enough to move console.log into the NODE_ENV condition (since tests have their own NODE_ENV)?

Copy link
Member Author

@dmsnell dmsnell Mar 1, 2017

Choose a reason for hiding this comment

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

not sure what you mean @aduth - they both log to the console but logging to the console isn't the problem. the thrown error halts the execution of the current JavaScript thread and that causes the big problem because it kills code which does nothing more than import the broken modules

it's my belief right now that we want to make an annoying console message so that any of us can quickly identify the failures in production but we want to prevent those failures from cascading outward thus removing the error

Copy link
Contributor

Choose a reason for hiding this comment

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

it's my belief right now that we want to make an annoying console message so that any of us can quickly identify the failures in production but we want to prevent those failures from cascading outward thus removing the error

Makes sense 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add in some styling to differentiate our Calypso framework warnings from React errors? For example:

console.error( `%c ${ error Message }`, 'color:white; background:black;' );

Copy link
Member Author

Choose a reason for hiding this comment

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

in f987c75 I added some styling @gwwar - wha'd'ya think?

screen shot 2017-03-01 at 9 06 14 pm

Recently the data layer experienced a total failure when #11490 merged
in and crashed when it failed to initialize the new middleware handler.

The fact that a key was requested for which no value existed led to
`config()` raising an `Error` which causes the entire middleware chain
to fail to build.

Now `config()` has been modified to only raise an actual `Error` when
the `NODE_ENV=developement` and instead in all other environments to
simply log a message to the browser console and return `undefined`. This
should allow us to still catch any mistakes by the obvious message while
preventing such otherwise-small errors from cascading out-of-control.
@dmsnell dmsnell force-pushed the update/fail-safe-config branch from b16c5a1 to 3f64db7 Compare March 2, 2017 00:11
@matticbot matticbot added the [Size] M Medium sized issue label Mar 2, 2017
Copy link
Contributor

@gwwar gwwar left a comment

Choose a reason for hiding this comment

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

Changes here look good to me 👍 I'm thinking we could add some static analysis as a next step in another PR. Probably a githook?

@matticbot matticbot added [Size] L Large sized issue and removed [Size] M Medium sized issue labels Mar 2, 2017
Instead of showing the same message in the console as in the browser we
can split the message into a styled and unstyled component.

This commit does just that using visual styling in the in-browser error
message to make it stand out among other warnings and messages.
@dmsnell dmsnell force-pushed the update/fail-safe-config branch from f987c75 to 9186e67 Compare March 2, 2017 04:27
@matticbot matticbot added the [Size] L Large sized issue label Mar 2, 2017
@dmsnell dmsnell mentioned this pull request Mar 2, 2017
4 tasks
@dmsnell
Copy link
Member Author

dmsnell commented Mar 3, 2017

Changes here look good to me 👍 I'm thinking we could add some static analysis as a next step in another PR. Probably a githook?

Yaaas! in the meantime I think we all need to start paying more attention to values assigned in the module scope that are runtime-dependent.

@dmsnell dmsnell merged commit af98ec7 into master Mar 3, 2017
@dmsnell dmsnell deleted the update/fail-safe-config branch March 3, 2017 21:52
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Mar 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework [Size] L Large sized issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants