errors.ts
This file
Path
src/utils/errors.ts
50 lines · 2.2 KiB · TypeScript
Last changed by
perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202
History of this fileTake it
The walk stopped after 200 commits: lines older than 648d39b point at it.
perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202
lines 1–2why, one step back1import {isFunction} from "../internal"2Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
lines 3–39why, one step back3export const errors =4 process.env.NODE_ENV !== "production"5 ? [6 // All error codes, starting by 0:7 function(plugin: string) {8 return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`9 },10 function(thing: string) {11 return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`12 },13 "This object has been frozen and should not be mutated",14 function(data: any) {15 return (16 "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " +17 data18 )19 },20 "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",21 "Immer forbids circular references",22 "The first or second argument to `produce` must be a function",23 "The third argument to `produce` must be a function or undefined",24 "First argument to `createDraft` must be a plain object, an array, or an immerable object",25 "First argument to `finishDraft` must be a draft returned by `createDraft`",26 function(thing: string) {27 return `'current' expects a draft, got: ${thing}`28 },29 "Object.defineProperty() cannot be used on an Immer draft",30 "Object.setPrototypeOf() cannot be used on an Immer draft",31 "Immer only supports deleting array indices",32 "Immer only supports setting array indices and the 'length' property",33 function(thing: string) {34 return `'original' expects a draft, got: ${thing}`35 }36 // Note: if more errors are added, the errorOffset in Patches.ts should be increased37 // See Patches.ts for additional errors38 ]39 : []docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b
line 40why, one step back40Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
lines 41–42why, one step back41export function die(error: number, ...args: any[]): never {42 if (process.env.NODE_ENV !== "production") {docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b
line 43why, one step back43 const e = errors[error]perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202
line 44why, one step back44 const msg = isFunction(e) ? e.apply(null, args as any) : edocs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b
lines 45–47why, one step back45 throw new Error(`[Immer] ${msg}`)46 }47 throw new Error(Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 48why, one step back48 `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b
lines 49–50why, one step back49 )50}