1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-03 18:35:09 +01:00

Log to sentry in addition to warning statements when checks fail in withContext

This commit is contained in:
Brett Sun 2016-07-06 11:58:54 +02:00
parent 2dce333c6a
commit 0d751d5986

View File

@ -76,10 +76,16 @@ export default function withContext(WrappedComponent, ...contextProps) {
const wrappedComponentName = getDisplayName(WrappedComponent); const wrappedComponentName = getDisplayName(WrappedComponent);
if (!contextProps.length) { if (!contextProps.length) {
console.logGlobal(
new Error('Used `withContext` without supplying any items to inject from the ' +
"component's context"),
{ wrappedComponentName }
);
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.warn(`Used withContext on ${wrappedComponentName} without supplying any ` + console.warn(`Either add context types to ${wrappedComponentName} or remove ` +
"items to inject from the component's context. Ignoring..."); '`withContext` from it');
} }
return WrappedComponent; return WrappedComponent;
@ -90,11 +96,17 @@ export default function withContext(WrappedComponent, ...contextProps) {
if (contextDef) { if (contextDef) {
Object.assign(types, contextDef.contextTypes); Object.assign(types, contextDef.contextTypes);
} else if (process.env.NODE_ENV !== 'production') { } else {
console.logGlobal(
new Error('No context type was matched when adding context through `withContext`'),
{ contextProp, wrappedComponentName }
);
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.warn(`No context types were found for '${contextProp}' when adding context ` + console.warn(`Make sure to add the context type information for ${contextProp} ` +
`to ${wrappedComponentName}. Make sure to add the context information ` + "to 'with_context.js.");
'with_context.js.'); }
} }
return types; return types;
@ -105,9 +117,16 @@ export default function withContext(WrappedComponent, ...contextProps) {
// Check if the expected context was available // Check if the expected context was available
Object.keys(contextTypes).forEach((contextType) => { Object.keys(contextTypes).forEach((contextType) => {
if (!context[contextType]) { if (!context[contextType]) {
console.logGlobal(
new Error('Expected context type did not exist in context when mounting ' +
'component through `withContext`'),
{ contextType, wrappedComponentName }
);
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.warn(`Expected '${contextType}' did not exist in ` + console.warn(`Missing ${contextType} from context in ${wrappedComponentName}`);
`${wrappedComponentName}'s context during mounting`); }
} }
}); });
} }