errors.ts
This file
Path
src/utils/errors.ts
48 lines · 2.1 KiB · TypeScript
Last changed by
Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
History of this fileTake it
The walk stopped after 200 commits: lines older than e4fd7d3 point at it.
Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
lines 1–37why, one step back1export const errors =2 process.env.NODE_ENV !== "production"3 ? [4 // All error codes, starting by 0:5 function(plugin: string) {6 return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`7 },8 function(thing: string) {9 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}'`10 },11 "This object has been frozen and should not be mutated",12 function(data: any) {13 return (14 "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " +15 data16 )17 },18 "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",19 "Immer forbids circular references",20 "The first or second argument to `produce` must be a function",21 "The third argument to `produce` must be a function or undefined",22 "First argument to `createDraft` must be a plain object, an array, or an immerable object",23 "First argument to `finishDraft` must be a draft returned by `createDraft`",24 function(thing: string) {25 return `'current' expects a draft, got: ${thing}`26 },27 "Object.defineProperty() cannot be used on an Immer draft",28 "Object.setPrototypeOf() cannot be used on an Immer draft",29 "Immer only supports deleting array indices",30 "Immer only supports setting array indices and the 'length' property",31 function(thing: string) {32 return `'original' expects a draft, got: ${thing}`33 }34 // Note: if more errors are added, the errorOffset in Patches.ts should be increased35 // See Patches.ts for additional errors36 ]37 : []chore(deps): bump hosted-git-info from 2.8.8 to 2.8.9 (#795)dependabot[bot]before adoptione4fd7d3
line 38why, one step back38Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
lines 39–40why, one step back39export function die(error: number, ...args: any[]): never {40 if (process.env.NODE_ENV !== "production") {chore(deps): bump hosted-git-info from 2.8.8 to 2.8.9 (#795)dependabot[bot]before adoptione4fd7d3
line 41why, one step back41 const e = errors[error]Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 42why, one step back42 const msg = typeof e === "function" ? e.apply(null, args as any) : echore(deps): bump hosted-git-info from 2.8.8 to 2.8.9 (#795)dependabot[bot]before adoptione4fd7d3
lines 43–45why, one step back43 throw new Error(`[Immer] ${msg}`)44 }45 throw new Error(Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 46why, one step back46 `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`chore(deps): bump hosted-git-info from 2.8.8 to 2.8.9 (#795)dependabot[bot]before adoptione4fd7d3
lines 47–48why, one step back47 )48}