Skip to content

Commit

Permalink
fix: stop hiding error details in production (remirror#1280)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocavue authored Oct 1, 2021
1 parent ea411b2 commit f17c2bb
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 90 deletions.
6 changes: 6 additions & 0 deletions .changeset/three-poets-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@remirror/core-constants': patch
'@remirror/core-helpers': patch
---

Stop hiding error details in production.
6 changes: 0 additions & 6 deletions docs/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ This page contains the documented errors that occur while using `remirror`. Curr

<br />

### RMR0000

> Production Error
An error occurred in production and details are intentionally being hidden.

### RMR0001

> Unknown Error
Expand Down
5 changes: 4 additions & 1 deletion packages/remirror__core-constants/src/error-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
* reference the errors within search engines.
*/
export enum ErrorConstant {
/** An error occurred in production. Details shall be hidden. */
/** An error occurred in production. Details shall be hidden.
*
* @deprecated - We don't hide the error details in production anymore.
*/
PROD = 'RMR0000',

/** An error happened but we're not quite sure why. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ It seems you're trying to set the value of the property (a) on a frozen object.
For more information visit https://remirror.io/docs/errors#rmr0005"
`;

exports[`invariant should throw generic error in production 1`] = `
"An error occurred with the \`Remirror\` setup in production. Any details are purposefully being withheld.
For more information visit https://remirror.io/docs/errors#rmr0000"
`;

exports[`invariant should throw with a code 1`] = `
"Command method names must be unique within the editor.
Expand Down
8 changes: 0 additions & 8 deletions packages/remirror__core-helpers/__tests__/core-errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,4 @@ describe('invariant', () => {
invariant(false, { code: ErrorConstant.DUPLICATE_COMMAND_NAMES }),
).toThrowErrorMatchingSnapshot();
});

it('should throw generic error in production', () => {
process.env.NODE_ENV = 'production';

expect(() =>
invariant(false, { code: ErrorConstant.DUPLICATE_COMMAND_NAMES, message: 'Never shown' }),
).toThrowErrorMatchingSnapshot();
});
});
117 changes: 50 additions & 67 deletions packages/remirror__core-helpers/src/core-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,56 @@ import { includes, isString, values } from './core-helpers';
*/
const ERROR_INFORMATION_URL = 'https://remirror.io/docs/errors';

let errorMessageMap: Partial<Record<ErrorConstant, string>> = {};

// This will be removed in a production environment.
if (process.env.NODE_ENV !== 'production') {
errorMessageMap = {
[ErrorConstant.PROD]:
'An error occurred with the `Remirror` setup in production. Any details are purposefully being withheld.',
[ErrorConstant.UNKNOWN]: "An error occurred but we're not quite sure why. 🧐",
[ErrorConstant.INVALID_COMMAND_ARGUMENTS]:
'The arguments passed to the command method were invalid.',
[ErrorConstant.CUSTOM]: 'This is a custom error, possibly thrown by an external library.',
[ErrorConstant.CORE_HELPERS]:
'An error occurred in a function called from the `@remirror/core-helpers` library.',
[ErrorConstant.MUTATION]: 'Mutation of immutable value detected.',
[ErrorConstant.INTERNAL]:
'This is an error which should not occur and is internal to the remirror codebase.',
[ErrorConstant.MISSING_REQUIRED_EXTENSION]: 'Your editor is missing a required extension.',
[ErrorConstant.MANAGER_PHASE_ERROR]:
'This occurs when accessing a method or property before it is available.',
[ErrorConstant.INVALID_GET_EXTENSION]:
'The user requested an invalid extension from the getExtensions method. Please check the `createExtensions` return method is returning an extension with the defined constructor.',
[ErrorConstant.INVALID_MANAGER_ARGUMENTS]:
'Invalid value(s) passed into `Manager` constructor. Only `Presets` and `Extensions` are supported.',
[ErrorConstant.SCHEMA]:
"There is a problem with the schema or you are trying to access a node / mark that doesn't exists.",
[ErrorConstant.HELPERS_CALLED_IN_OUTER_SCOPE]:
'The `helpers` method which is passed into the ``create*` method should only be called within returned method since it relies on an active view (not present in the outer scope).',
[ErrorConstant.INVALID_MANAGER_EXTENSION]:
'You requested an invalid extension from the manager.',
[ErrorConstant.DUPLICATE_COMMAND_NAMES]:
'Command method names must be unique within the editor.',
[ErrorConstant.DUPLICATE_HELPER_NAMES]: 'Helper method names must be unique within the editor.',
[ErrorConstant.NON_CHAINABLE_COMMAND]: 'Attempted to chain a non chainable command.',
[ErrorConstant.INVALID_EXTENSION]: 'The provided extension is invalid.',
[ErrorConstant.INVALID_CONTENT]: 'The content provided to the editor is not supported.',
[ErrorConstant.INVALID_NAME]: 'An invalid name was used for the extension.',
[ErrorConstant.EXTENSION]:
'An error occurred within an extension. More details should be made available.',
[ErrorConstant.EXTENSION_SPEC]:
'The spec was defined without calling the `defaults`, `parse` or `dom` methods.',
[ErrorConstant.EXTENSION_EXTRA_ATTRIBUTES]:
'Extra attributes must either be a string or an object.',
[ErrorConstant.INVALID_SET_EXTENSION_OPTIONS]:
'A call to `extension.setOptions` was made with invalid keys.',
[ErrorConstant.REACT_PROVIDER_CONTEXT]:
'`useRemirrorContext` was called outside of the `remirror` context. It can only be used within an active remirror context created by the `<Remirror />`.',
[ErrorConstant.REACT_GET_ROOT_PROPS]:
'`getRootProps` has been attached to the DOM more than once. It should only be attached to the dom once per editor.',
[ErrorConstant.REACT_EDITOR_VIEW]: 'A problem occurred adding the editor view to the dom.',
[ErrorConstant.REACT_CONTROLLED]: 'There is a problem with your controlled editor setup.',
[ErrorConstant.REACT_NODE_VIEW]:
'Something went wrong with your custom ReactNodeView Component.',
[ErrorConstant.REACT_GET_CONTEXT]:
'You attempted to call `getContext` provided by the `useRemirror` prop during the first render of the editor. This is not possible and should only be after the editor first mounts.',
[ErrorConstant.REACT_COMPONENTS]: 'An error occurred within a remirror component.',
[ErrorConstant.REACT_HOOKS]: 'An error occurred within a remirror hook.',

[ErrorConstant.I18N_CONTEXT]: 'You called `useI18n()` outside of an `I18nProvider` context.',
};
}
const errorMessageMap: Partial<Record<ErrorConstant, string>> = {
[ErrorConstant.UNKNOWN]: "An error occurred but we're not quite sure why. 🧐",
[ErrorConstant.INVALID_COMMAND_ARGUMENTS]:
'The arguments passed to the command method were invalid.',
[ErrorConstant.CUSTOM]: 'This is a custom error, possibly thrown by an external library.',
[ErrorConstant.CORE_HELPERS]:
'An error occurred in a function called from the `@remirror/core-helpers` library.',
[ErrorConstant.MUTATION]: 'Mutation of immutable value detected.',
[ErrorConstant.INTERNAL]:
'This is an error which should not occur and is internal to the remirror codebase.',
[ErrorConstant.MISSING_REQUIRED_EXTENSION]: 'Your editor is missing a required extension.',
[ErrorConstant.MANAGER_PHASE_ERROR]:
'This occurs when accessing a method or property before it is available.',
[ErrorConstant.INVALID_GET_EXTENSION]:
'The user requested an invalid extension from the getExtensions method. Please check the `createExtensions` return method is returning an extension with the defined constructor.',
[ErrorConstant.INVALID_MANAGER_ARGUMENTS]:
'Invalid value(s) passed into `Manager` constructor. Only `Presets` and `Extensions` are supported.',
[ErrorConstant.SCHEMA]:
"There is a problem with the schema or you are trying to access a node / mark that doesn't exists.",
[ErrorConstant.HELPERS_CALLED_IN_OUTER_SCOPE]:
'The `helpers` method which is passed into the ``create*` method should only be called within returned method since it relies on an active view (not present in the outer scope).',
[ErrorConstant.INVALID_MANAGER_EXTENSION]: 'You requested an invalid extension from the manager.',
[ErrorConstant.DUPLICATE_COMMAND_NAMES]: 'Command method names must be unique within the editor.',
[ErrorConstant.DUPLICATE_HELPER_NAMES]: 'Helper method names must be unique within the editor.',
[ErrorConstant.NON_CHAINABLE_COMMAND]: 'Attempted to chain a non chainable command.',
[ErrorConstant.INVALID_EXTENSION]: 'The provided extension is invalid.',
[ErrorConstant.INVALID_CONTENT]: 'The content provided to the editor is not supported.',
[ErrorConstant.INVALID_NAME]: 'An invalid name was used for the extension.',
[ErrorConstant.EXTENSION]:
'An error occurred within an extension. More details should be made available.',
[ErrorConstant.EXTENSION_SPEC]:
'The spec was defined without calling the `defaults`, `parse` or `dom` methods.',
[ErrorConstant.EXTENSION_EXTRA_ATTRIBUTES]:
'Extra attributes must either be a string or an object.',
[ErrorConstant.INVALID_SET_EXTENSION_OPTIONS]:
'A call to `extension.setOptions` was made with invalid keys.',
[ErrorConstant.REACT_PROVIDER_CONTEXT]:
'`useRemirrorContext` was called outside of the `remirror` context. It can only be used within an active remirror context created by the `<Remirror />`.',
[ErrorConstant.REACT_GET_ROOT_PROPS]:
'`getRootProps` has been attached to the DOM more than once. It should only be attached to the dom once per editor.',
[ErrorConstant.REACT_EDITOR_VIEW]: 'A problem occurred adding the editor view to the dom.',
[ErrorConstant.REACT_CONTROLLED]: 'There is a problem with your controlled editor setup.',
[ErrorConstant.REACT_NODE_VIEW]: 'Something went wrong with your custom ReactNodeView Component.',
[ErrorConstant.REACT_GET_CONTEXT]:
'You attempted to call `getContext` provided by the `useRemirror` prop during the first render of the editor. This is not possible and should only be after the editor first mounts.',
[ErrorConstant.REACT_COMPONENTS]: 'An error occurred within a remirror component.',
[ErrorConstant.REACT_HOOKS]: 'An error occurred within a remirror hook.',

[ErrorConstant.I18N_CONTEXT]: 'You called `useI18n()` outside of an `I18nProvider` context.',
};

/**
* Checks whether the passed code is an `ErrorConstant`.
Expand Down Expand Up @@ -149,13 +139,6 @@ export function invariant(condition: unknown, options: RemirrorErrorOptions): as
return;
}

// When not in 'DEV' strip the message but still throw
if (process.env.NODE_ENV === 'production') {
throw RemirrorError.create({ code: ErrorConstant.PROD });
}

// When not in production we allow the message to pass through
// **This is never called in production builds.**
throw RemirrorError.create(options);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/remirror__extension-embed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"access": "public"
},
"@remirror": {
"sizeLimit": "10 KB"
"sizeLimit": "20 KB"
},
"rn:dev": "src/index.ts"
}
2 changes: 1 addition & 1 deletion support/root/.size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
},
{
"name": "@remirror/extension-embed",
"limit": "10 KB",
"limit": "20 KB",
"path": "packages/remirror__extension-embed/dist/remirror-extension-embed.browser.esm.js",
"ignore": ["@remirror/pm", "@remirror/core", "@remirror/messages"],
"running": false,
Expand Down

0 comments on commit f17c2bb

Please sign in to comment.