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

move combine reducers sanity check #717 #761

Merged
merged 1 commit into from
Sep 23, 2015

Conversation

ellbee
Copy link
Contributor

@ellbee ellbee commented Sep 20, 2015

Creates and logs sanity check error during combineReducers, but only throws on first invocation. Addresses #717.

if (sanityError) {
console.error(sanityError.message);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure that this console.error is necessary, the error is thrown very shortly afterwards. And if it is useful, it has just occurred to me that it should probably log error.stack if available.

Copy link
Member

Choose a reason for hiding this comment

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

console.logs/errors are a no-no in the library because they are normally uncatchable and noisy (and console sometimes doesn't exist). A thrown Error is best because that follows normal JS patterns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is to delay throwing the error but log as soon as possible. The console.error was suggested by @gaearon in the second comment of issue #717. I do agree that this is noisy, as the error is thrown shortly afterwards and you end up with the same error logged twice in succession.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think console.error is inherently bad if it is a sign of an error. React also uses console.error for propTypes warnings because they're not really warnings: if you have them, you need to fix them. The nice thing about console.error is that it prints the stack trace, unlike its friends.

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't it disable logging in the production build? Maybe the same thing should happen here. A log isn't bad for devs, but shouldn't make its way to production.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we previously console.error'd only in development, too.
I think we should hide this console.error behind the dev flag as well.

Of course, if it's not helpful, it's better to remove it. I'm not sure whether the confusion from error printed twice is bigger than the help from a proper stack trace. Thoughts?

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 played with this a bit more using devtools and I don't think the console.error is helpful. Throwing sanityError logs the stack trace from where the error was created in combineReducers, so the two stack traces in the log are actually the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, okay. Then let's remove it! Thanks for checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, will do.

@ellbee ellbee force-pushed the move_combineReducers_sanity_check branch from 0354a42 to df287f3 Compare September 21, 2015 21:45
@ellbee
Copy link
Contributor Author

ellbee commented Sep 21, 2015

Updated to create but not log the error during combineReducers. The error is thrown on first invocation.

@ellbee ellbee force-pushed the move_combineReducers_sanity_check branch from df287f3 to 7bc27de Compare September 22, 2015 09:09
@ellbee
Copy link
Contributor Author

ellbee commented Sep 22, 2015

Added production check around sanity check (#771)

@gaearon
Copy link
Contributor

gaearon commented Sep 22, 2015

It's only OK to check for production env for errors we don't throw. Both environments should throw in the same conditions so error stack traces from production are reproducible in development. Please see #771 (comment).

@ellbee
Copy link
Contributor Author

ellbee commented Sep 22, 2015

Got it. I'll revert back to how it was previously.

@gaearon
Copy link
Contributor

gaearon commented Sep 22, 2015

Sure, thanks!

@ellbee ellbee force-pushed the move_combineReducers_sanity_check branch from 7bc27de to c2bf13c Compare September 22, 2015 11:31
gaearon added a commit that referenced this pull request Sep 23, 2015
@gaearon gaearon merged commit 3628ad0 into reduxjs:master Sep 23, 2015
@ellbee ellbee deleted the move_combineReducers_sanity_check branch November 29, 2015 14:18
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.

3 participants