-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Rewrite Redux core error messages #4055
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"sandboxes": [ | ||
"vanilla", | ||
"vanilla-ts" | ||
], | ||
"node": "14" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
{ | ||
"0": "It looks like you are passing several store enhancers to createStore(). This is not supported. Instead, compose them together to a single function.", | ||
"1": "Expected the enhancer to be a function.", | ||
"2": "Expected the reducer to be a function.", | ||
"0": "It looks like you are passing several store enhancers to createStore(). This is not supported. Instead, compose them together to a single function. See https://redux.js.org/tutorials/fundamentals/part-4-store#creating-a-store-with-enhancers for an example.", | ||
"1": "Expected the enhancer to be a function. Instead, received: ''", | ||
"2": "Expected the root reducer to be a function. Instead, received: ''", | ||
"3": "You may not call store.getState() while the reducer is executing. The reducer has already received the state as an argument. Pass it down from the top reducer instead of reading it from the store.", | ||
"4": "Expected the listener to be a function.", | ||
"4": "Expected the listener to be a function. Instead, received: ''", | ||
"5": "You may not call store.subscribe() while the reducer is executing. If you would like to be notified after the store has been updated, subscribe from a component and invoke store.getState() in the callback to access the latest state. See https://redux.js.org/api/store#subscribelistener for more details.", | ||
"6": "You may not unsubscribe from a store listener while the reducer is executing. See https://redux.js.org/api/store#subscribelistener for more details.", | ||
"7": "Actions must be plain objects. Use custom middleware for async actions.", | ||
"8": "Actions may not have an undefined \"type\" property. Have you misspelled a constant?", | ||
"7": "Actions must be plain objects. Instead, the actual type was: ''. You may need to add middleware to your store setup to handle dispatching other values, such as 'redux-thunk' to handle dispatching functions. See https://redux.js.org/tutorials/fundamentals/part-4-store#middleware and https://redux.js.org/tutorials/fundamentals/part-6-async-logic#using-the-redux-thunk-middleware for examples.", | ||
"8": "Actions may not have an undefined \"type\" property. You may have misspelled an action type string constant.", | ||
"9": "Reducers may not dispatch actions.", | ||
"10": "Expected the nextReducer to be a function.", | ||
"11": "Expected the observer to be an object.", | ||
"12": "bindActionCreators expected an object or a function, instead received . Did you write \"import ActionCreators from\" instead of \"import * as ActionCreators from\"?", | ||
"13": "Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.", | ||
"14": "Reducer \"\" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.", | ||
"15": "Reducer \"\" returned undefined when probed with a random type. Don't try to handle or other actions in \"redux/*\" namespace. They are considered private. Instead, you must return the current state for any unknown actions, unless it is undefined, in which case you must return the initial state, regardless of the action type. The initial state may not be undefined, but can be null.", | ||
"16": "Super expression must either be null or a function" | ||
"10": "Expected the nextReducer to be a function. Instead, received: '", | ||
"11": "Expected the observer to be an object. Instead, received: ''", | ||
"12": "The slice reducer for key \"\" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.", | ||
"13": "The slice reducer for key \"\" returned undefined when probed with a random type. Don't try to handle or other actions in \"redux/*\" namespace. They are considered private. Instead, you must return the current state for any unknown actions, unless it is undefined, in which case you must return the initial state, regardless of the action type. The initial state may not be undefined, but can be null.", | ||
"14": "When called with an action of type , the slice reducer for key \"\" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.", | ||
"15": "Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.", | ||
"16": "bindActionCreators expected an object or a function, but instead received: ''. Did you write \"import ActionCreators from\" instead of \"import * as ActionCreators from\"?" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
export function kindOf(val: any): string { | ||
let typeOfVal: string = typeof val | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
// Inlined / shortened version of `kindOf` from https://github.com/jonschlinkert/kind-of | ||
function miniKindOf(val: any) { | ||
if (val === void 0) return 'undefined' | ||
if (val === null) return 'null' | ||
|
||
const type = typeof val | ||
switch (type) { | ||
case 'boolean': | ||
case 'string': | ||
case 'number': | ||
case 'symbol': | ||
case 'function': { | ||
return type | ||
} | ||
} | ||
|
||
if (Array.isArray(val)) return 'array' | ||
if (isDate(val)) return 'date' | ||
if (isError(val)) return 'error' | ||
|
||
const constructorName = ctorName(val) | ||
switch (constructorName) { | ||
case 'Symbol': | ||
case 'Promise': | ||
case 'WeakMap': | ||
case 'WeakSet': | ||
case 'Map': | ||
case 'Set': | ||
return constructorName | ||
} | ||
|
||
// other | ||
return type.slice(8, -1).toLowerCase().replace(/\s/g, '') | ||
} | ||
|
||
function ctorName(val: any): string | null { | ||
return typeof val.constructor === 'function' ? val.constructor.name : null | ||
} | ||
|
||
function isError(val: any) { | ||
return ( | ||
val instanceof Error || | ||
(typeof val.message === 'string' && | ||
val.constructor && | ||
typeof val.constructor.stackTraceLimit === 'number') | ||
) | ||
} | ||
|
||
function isDate(val: any) { | ||
if (val instanceof Date) return true | ||
return ( | ||
typeof val.toDateString === 'function' && | ||
typeof val.getDate === 'function' && | ||
typeof val.setDate === 'function' | ||
) | ||
} | ||
|
||
typeOfVal = miniKindOf(val) | ||
} | ||
|
||
return typeOfVal | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this missing a char or '' to get replaced that I'm not seeing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a template literal interpolation there:
and that doesn't get included in the extracted message.
I'll add single quotes around it, though.