You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,15 @@
2
2
3
3
## Unreleased
4
4
5
+
-`TypeCheckError` now supports a single object parameter and still accepts positional constructor arguments for backward compatibility.
6
+
-`TypeCheckError.throw()` now throws `TypeCheckErrorFailure` (which extends `MobxKeystoneError`), and union snapshot mismatches now throw `SnapshotTypeMismatchError` (also extending `MobxKeystoneError`) with structured metadata.
7
+
- Snapshot processing now throws a dedicated `SnapshotProcessingError` (extends `MobxKeystoneError`) across `fromSnapshot` / `applySnapshot` / reconciliation paths.
8
+
-`SnapshotProcessingError` messages now include enriched diagnostics text (full deep path, value preview, and model trail when available), making it much easier to pinpoint failing nested fields quickly.
9
+
-`SnapshotProcessingError`, `SnapshotTypeMismatchError`, and `TypeCheckError` now share one diagnostics message formatter and a consistent layout: `MSG - Path: ... - Value: ... - Model trail: ...`, so error output is predictable across snapshot and type-check flows.
10
+
- Improved snapshot/type error diagnostics end-to-end: path-aware messages across `fromSnapshot` / `applySnapshot` / union snapshot processing, plus structured error metadata (`path`, `expectedTypeName`, `actualValue`, `typeCheckedValue`, `modelTrail`) on thrown errors when available for easier tooling and debugging.
11
+
- Note: because diagnostics were improved, error message text changed in these paths (`TypeCheckError`, `SnapshotProcessingError`, `SnapshotTypeMismatchError`, and related snapshot/apply patches flows). If you assert exact error strings, update expectations.
12
+
-`applyPatches` reconciliation errors now also include accurate patch paths in diagnostics.
13
+
5
14
## 1.13.0
6
15
7
16
- Added array syntax as a `tProp` union shorthand, for example `tProp([String, Number])` as an alias for `tProp(types.or(String, Number))`.
Copy file name to clipboardExpand all lines: apps/site/docs/runtimeTypeChecking.mdx
+13-2Lines changed: 13 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,7 +62,11 @@ In all cases the returned value will be `null` if there are no errors or an inst
62
62
-`path: Path` - Sub-path where the type-check failed, or an empty array if the actual object/value failed the type-check.
63
63
-`expectedTypeName: string` - String representation of the expected type.
64
64
-`actualValue: any` - The actual value/sub-value that failed the type-check
65
-
-`throw(typeCheckedValue: any)` - Throws the error as an exception.
65
+
-`typeCheckedValue?: any` - The value/object where the type-check was invoked.
66
+
-`modelTrail?: readonly string[]` - Optional model/type trail (for example during snapshot processing of nested models).
67
+
-`throw()` - Throws a `TypeCheckErrorFailure` as an exception.
68
+
69
+
`TypeCheckErrorFailure` extends `MobxKeystoneError`, so `instanceof MobxKeystoneError` checks work on thrown failures.
66
70
67
71
While models are usually automatically type-checked, it is worth noting that other values (primitives, plain objects, arrays) are not until they become attached to some model. If you need to type-check those before they become attached to a model it is always possible to use `typeCheck(type, value)` as shown previously to trigger a manual validation.
68
72
@@ -139,6 +143,7 @@ const shapeType = types.or(
139
143
```
140
144
141
145
The dispatcher receives the snapshot and must return one of the provided union types.
146
+
When no union branch matches during snapshot conversion, `types.or` throws `SnapshotTypeMismatchError` (a `MobxKeystoneError`) with path/type/value metadata.
Copy file name to clipboardExpand all lines: apps/site/docs/snapshots.mdx
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -194,6 +194,8 @@ applySnapshot(todo, {
194
194
195
195
In the case above, only a single patch will be generated (for the `done` property), and the same todo instance will be reused (since they have the same model ID).
196
196
197
+
When `fromSnapshot` or `applySnapshot` fails due to snapshot processing issues, it throws `SnapshotProcessingError` (extends `MobxKeystoneError`) and includes diagnostic metadata such as `path`, `actualSnapshot` (when available), and `modelTrail` (when available). Its error message is also enriched with this metadata (plus a safe value preview when available).
0 commit comments