Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 1b70ad5 point at it.

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

lines 1–37why, one step back
1export 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 : []

fix: undraftable values should not be cloned for patches, fixes #676Michel Weststratebefore adoption1b70ad5

line 38why, one step back
38

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

lines 39–40why, one step back
39export function die(error: number, ...args: any[]): never {
40 if (process.env.NODE_ENV !== "production") {

fix: undraftable values should not be cloned for patches, fixes #676Michel Weststratebefore adoption1b70ad5

line 41why, one step back
41 const e = errors[error]

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 42why, one step back
42 const msg = typeof e === "function" ? e.apply(null, args as any) : e

fix: undraftable values should not be cloned for patches, fixes #676Michel Weststratebefore adoption1b70ad5

lines 43–45why, one step back
43 throw new Error(`[Immer] ${msg}`)
44 }45 throw new Error(

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 46why, one step back
46 `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`

fix: undraftable values should not be cloned for patches, fixes #676Michel Weststratebefore adoption1b70ad5

lines 47–48why, one step back
47 )
48}