Skip to content

Commit 58bb10e

Browse files
committed
feat(core): extend error metadata handling in with() method
Refactored `DefinedError.with()` to improve metadata merging logic and type safety. Updated tests to verify region-based metadata inclusion.
1 parent 5057593 commit 58bb10e

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

packages/core/__tests__/caller-trace.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe("ThatError Location Anchoring", () => {
8989
* 💡 THE ANCHOR POINT
9090
* We call .at() here to explicitly mark this line as the "Crime Scene".
9191
*/
92-
return AppError.SYNC_ERR().with(void 0, {stage: 'init'});
92+
return AppError.SYNC_ERR().with(void 0, {stage: 'init'}).with(void 0, {region: "CN"});
9393
}
9494

9595
const err = businessFunction();
@@ -100,7 +100,7 @@ describe("ThatError Location Anchoring", () => {
100100
expect(topFrame).toContain("businessFunction");
101101
expect(topFrame).toContain(currentFileName);
102102

103-
expect(metaOf(err)).toEqual({stage: 'init'});
103+
expect(metaOf(err)).toEqual({stage: 'init', region: "CN"});
104104

105105
// 🛡️ Noise Removal: The factory internals (define.ts) must be sliced off.
106106
expect(topFrame).not.toContain("define.ts");

packages/core/src/define.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ export function That<const M extends ErrorMap>(
5252
Error.captureStackTrace(this, _caller);
5353
}
5454

55-
with<Me extends Record<string, unknown>>(options?: ErrorOptions, meta?: Me) {
55+
with<Mt extends Record<string, unknown>>(options?: ErrorOptions, meta?: Mt) {
5656
this.cause = options?.cause;
5757
this[MetaField] = {...this[MetaField], ...meta};
58-
return this as this & DefinedError<Extract<keyof M, string>, ExtractPayload<M[Extract<keyof M, string>]>, Record<string, unknown> & Me>;
58+
return this as DefinedError<Code, Payload, Mt>;
5959
}
6060

6161
is<K extends string, S extends ErrorSpec>(errorCase: ErrorCase<K, S>): this is DefinedError<K, ExtractPayload<S>> {

packages/core/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface DefinedError<
1515
readonly [CodeField]: Code;
1616
[MetaField]: Meta;
1717

18-
with<Me extends Record<string, unknown>>(options?: ErrorOptions, meta?: Me): this & DefinedError<Code, Payload, Meta & Me>;
18+
with<Me extends Record<string, unknown>>(options?: ErrorOptions, meta?: Me): DefinedError<Code, Payload, Meta & Me>;
1919

2020
is<K extends string, S extends ErrorSpec>(errorCase: ErrorCase<K, S>): this is DefinedError<K, ExtractPayload<S>>;
2121
}

0 commit comments

Comments
 (0)