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

[Fiber] Replace throw new Error with invariant module #8926

Merged
merged 3 commits into from
Feb 6, 2017

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Feb 3, 2017

The umbrella task says they should have "sensible messages." Does this include internal invariants (ones that only throw if there's a bug in React)?

if (newChildren == null) {
throw new Error('An iterable object provided no iterator.');
}
invariant(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't a behavior change in your PR, but we shouldn't have any DEV-only exceptions. Can we make this a warning (either here in a new PR)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. There's an identical non-dev check that happens below. I'll refactor so there's only one check.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, we (necessarily) call the iterator twice right? We tried to avoid that before and the code was super super messy.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was thinking if there's no iterator in DEV, skip the key warning and go straight to the prod invariant, which will throw.

@gaearon
Copy link
Collaborator

gaearon commented Feb 4, 2017

The umbrella task says they should have "sensible messages." Does this include internal invariants (ones that only throw if there's a bug in React)?

I meant that we should make sure any internal variants clearly explain this is a bug in React and ask to file an issue.

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

Let's add "This is likely a bug in React." to all internal messages?

@acdlite
Copy link
Collaborator Author

acdlite commented Feb 6, 2017

@gaearon Updated

@@ -72,6 +72,9 @@ const {
Deletion,
} = ReactTypeOfSideEffect;

const internalErrorMessage =
'This error is likely caused by a bug in React. Please file an issue.';
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will count against the byte size, is this intentional?
It doesn’t matter that much in the grand scheme of things, just wondering if this was intended or not.
If you just hardcoded it everywhere then it would get stripped out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hrrm, didn't think about that. Don't think it makes a substantial difference but we can change later.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer we do it now so it (or similar patterns) don't keep spreading.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Me too, let's inline please.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes plz.

}
invariant(
typeof iteratorFn === 'function',
'An object is not an iterable. (%s)',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure we can count this as an internal error? The object is supplied by the user code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, my bad

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is correct because if it's not an iterator then we shouldn't have reached this code path.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Unless user specified code returns something different the second time we read @@iterator, no?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It could be a getter.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That check doesn't check the type of the iterator.

@@ -727,15 +739,17 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
case Fragment:
return updateFragment(current, workInProgress);
default:
throw new Error('Unknown unit of work tag');
invariant(false, 'Unknown unit of work tag');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also internal.

throw new Error('There should always be pending or memoized props.');
}
invariant(
newProps !== null,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe worth checking for undefined too here and above? != null

Copy link
Collaborator Author

@acdlite acdlite Feb 6, 2017

Choose a reason for hiding this comment

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

Yeah I'll loosen those up. Should do a pass at some point and change all our maybe types to null unions. Though props is currently an any, which is worse.

The message tells users that the error is likely due to a bug in React,
and that they should file an issue.
@acdlite acdlite merged commit a2c49f4 into facebook:master Feb 6, 2017
@gaearon
Copy link
Collaborator

gaearon commented Feb 6, 2017

Would you inline in a follow up?

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

Successfully merging this pull request may close these issues.

5 participants