From f17c2bbb599fd7b4d354080293ce210af6b89825 Mon Sep 17 00:00:00 2001 From: ocavue Date: Fri, 1 Oct 2021 20:18:34 +0800 Subject: [PATCH] fix: stop hiding error details in production (#1280) --- .changeset/three-poets-hunt.md | 6 + docs/errors.md | 6 - .../src/error-constants.ts | 5 +- .../__snapshots__/core-errors.spec.ts.snap | 6 - .../__tests__/core-errors.spec.ts | 8 -- .../remirror__core-helpers/src/core-errors.ts | 117 ++++++++---------- .../remirror__extension-embed/package.json | 2 +- support/root/.size-limit.json | 2 +- 8 files changed, 62 insertions(+), 90 deletions(-) create mode 100644 .changeset/three-poets-hunt.md diff --git a/.changeset/three-poets-hunt.md b/.changeset/three-poets-hunt.md new file mode 100644 index 0000000000..f958719227 --- /dev/null +++ b/.changeset/three-poets-hunt.md @@ -0,0 +1,6 @@ +--- +'@remirror/core-constants': patch +'@remirror/core-helpers': patch +--- + +Stop hiding error details in production. diff --git a/docs/errors.md b/docs/errors.md index 94d778ad5f..7245918cca 100644 --- a/docs/errors.md +++ b/docs/errors.md @@ -13,12 +13,6 @@ This page contains the documented errors that occur while using `remirror`. Curr
-### RMR0000 - -> Production Error - -An error occurred in production and details are intentionally being hidden. - ### RMR0001 > Unknown Error diff --git a/packages/remirror__core-constants/src/error-constants.ts b/packages/remirror__core-constants/src/error-constants.ts index 9b07e8f49b..bcbbf8b1e4 100644 --- a/packages/remirror__core-constants/src/error-constants.ts +++ b/packages/remirror__core-constants/src/error-constants.ts @@ -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. */ diff --git a/packages/remirror__core-helpers/__tests__/__snapshots__/core-errors.spec.ts.snap b/packages/remirror__core-helpers/__tests__/__snapshots__/core-errors.spec.ts.snap index 0225c209ac..3232cc8df7 100644 --- a/packages/remirror__core-helpers/__tests__/__snapshots__/core-errors.spec.ts.snap +++ b/packages/remirror__core-helpers/__tests__/__snapshots__/core-errors.spec.ts.snap @@ -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. diff --git a/packages/remirror__core-helpers/__tests__/core-errors.spec.ts b/packages/remirror__core-helpers/__tests__/core-errors.spec.ts index a9499eb519..b271ed1975 100644 --- a/packages/remirror__core-helpers/__tests__/core-errors.spec.ts +++ b/packages/remirror__core-helpers/__tests__/core-errors.spec.ts @@ -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(); - }); }); diff --git a/packages/remirror__core-helpers/src/core-errors.ts b/packages/remirror__core-helpers/src/core-errors.ts index 370a5c4eb3..f5d97693a5 100644 --- a/packages/remirror__core-helpers/src/core-errors.ts +++ b/packages/remirror__core-helpers/src/core-errors.ts @@ -9,66 +9,56 @@ import { includes, isString, values } from './core-helpers'; */ const ERROR_INFORMATION_URL = 'https://remirror.io/docs/errors'; -let errorMessageMap: Partial> = {}; - -// 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 ``.', - [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> = { + [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 ``.', + [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`. @@ -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); } diff --git a/packages/remirror__extension-embed/package.json b/packages/remirror__extension-embed/package.json index 3de87bb21e..bd9ec44f94 100644 --- a/packages/remirror__extension-embed/package.json +++ b/packages/remirror__extension-embed/package.json @@ -57,7 +57,7 @@ "access": "public" }, "@remirror": { - "sizeLimit": "10 KB" + "sizeLimit": "20 KB" }, "rn:dev": "src/index.ts" } diff --git a/support/root/.size-limit.json b/support/root/.size-limit.json index a1b196f1bb..ead1824689 100644 --- a/support/root/.size-limit.json +++ b/support/root/.size-limit.json @@ -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,