1 | const niceErrors = {
|
2 | 0: `Invalid value for configuration 'enforceActions', expected 'never', 'always' or 'observed'`,
|
3 | 1(annotationType, key: PropertyKey) {
|
4 | return `Cannot apply '${annotationType}' to '${key.toString()}': Field not found.`
|
5 | },
|
6 | |
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | 5: "'keys()' can only be used on observable objects, arrays, sets and maps",
|
18 | 6: "'values()' can only be used on observable objects, arrays, sets and maps",
|
19 | 7: "'entries()' can only be used on observable objects, arrays and maps",
|
20 | 8: "'set()' can only be used on observable objects, arrays and maps",
|
21 | 9: "'remove()' can only be used on observable objects, arrays and maps",
|
22 | 10: "'has()' can only be used on observable objects, arrays and maps",
|
23 | 11: "'get()' can only be used on observable objects, arrays and maps",
|
24 | 12: `Invalid annotation`,
|
25 | 13: `Dynamic observable objects cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)`,
|
26 | 14: "Intercept handlers should return nothing or a change object",
|
27 | 15: `Observable arrays cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)`,
|
28 | 16: `Modification exception: the internal structure of an observable array was changed.`,
|
29 | 17(index, length) {
|
30 | return `[mobx.array] Index out of bounds, ${index} is larger than ${length}`
|
31 | },
|
32 | 18: "mobx.map requires Map polyfill for the current browser. Check babel-polyfill or core-js/es6/map.js",
|
33 | 19(other) {
|
34 | return "Cannot initialize from classes that inherit from Map: " + other.constructor.name
|
35 | },
|
36 | 20(other) {
|
37 | return "Cannot initialize map from " + other
|
38 | },
|
39 | 21(dataStructure) {
|
40 | return `Cannot convert to map from '${dataStructure}'`
|
41 | },
|
42 | 22: "mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js",
|
43 | 23: "It is not possible to get index atoms from arrays",
|
44 | 24(thing) {
|
45 | return "Cannot obtain administration from " + thing
|
46 | },
|
47 | 25(property, name) {
|
48 | return `the entry '${property}' does not exist in the observable map '${name}'`
|
49 | },
|
50 | 26: "please specify a property",
|
51 | 27(property, name) {
|
52 | return `no observable property '${property.toString()}' found on the observable object '${name}'`
|
53 | },
|
54 | 28(thing) {
|
55 | return "Cannot obtain atom from " + thing
|
56 | },
|
57 | 29: "Expecting some object",
|
58 | 30: "invalid action stack. did you forget to finish an action?",
|
59 | 31: "missing option for computed: get",
|
60 | 32(name, derivation) {
|
61 | return `Cycle detected in computation ${name}: ${derivation}`
|
62 | },
|
63 | 33(name) {
|
64 | return `The setter of computed value '${name}' is trying to update itself. Did you intend to update an _observable_ value, instead of the computed property?`
|
65 | },
|
66 | 34(name) {
|
67 | return `[ComputedValue '${name}'] It is not possible to assign a new value to a computed value.`
|
68 | },
|
69 | 35: "There are multiple, different versions of MobX active. Make sure MobX is loaded only once or use `configure({ isolateGlobalState: true })`",
|
70 | 36: "isolateGlobalState should be called before MobX is running any reactions",
|
71 | 37(method) {
|
72 | return `[mobx] \`observableArray.${method}()\` mutates the array in-place, which is not allowed inside a derivation. Use \`array.slice().${method}()\` instead`
|
73 | },
|
74 | 38: "'ownKeys()' can only be used on observable objects",
|
75 | 39: "'defineProperty()' can only be used on observable objects"
|
76 | } as const
|
77 |
|
78 | const errors: typeof niceErrors = __DEV__ ? niceErrors : ({} as any)
|
79 |
|
80 | export function die(error: string | keyof typeof errors, ...args: any[]): never {
|
81 | if (__DEV__) {
|
82 | let e: any = typeof error === "string" ? error : errors[error]
|
83 | if (typeof e === "function") e = e.apply(null, args as any)
|
84 | throw new Error(`[MobX] ${e}`)
|
85 | }
|
86 | throw new Error(
|
87 | typeof error === "number"
|
88 | ? `[MobX] minified error nr: ${error}${
|
89 | args.length ? " " + args.map(String).join(",") : ""
|
90 | }. Find the full error at: https://github.com/mobxjs/mobx/blob/main/packages/mobx/src/errors.ts`
|
91 | : `[MobX] ${error}`
|
92 | )
|
93 | }
|