Skip to content

Commit 025c517

Browse files
committed
refactor(core): remove MetaField and simplify error metadata handling
1 parent 58bb10e commit 025c517

4 files changed

Lines changed: 5 additions & 19 deletions

File tree

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// noinspection ES6UnusedImports
22
import { describe, expect, test } from "bun:test";
3-
import { metaOf, That } from '@thaterror/core';
3+
import { That } from '@thaterror/core';
44
import { ResultAsync } from 'neverthrow';
55

66
describe("ThatError Location Anchoring", () => {
@@ -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'}).with(void 0, {region: "CN"});
92+
return AppError.SYNC_ERR().with(void 0);
9393
}
9494

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

103-
expect(metaOf(err)).toEqual({stage: 'init', region: "CN"});
104-
105103
// 🛡️ Noise Removal: The factory internals (define.ts) must be sliced off.
106104
expect(topFrame).not.toContain("define.ts");
107105

packages/core/src/define.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
type ErrorSpec,
1111
type ErrorUnionOfMap,
1212
type ExtractPayload,
13-
MetaField,
1413
PayloadField,
1514
ScopeField
1615
} from "./types";
@@ -33,7 +32,6 @@ export function That<const M extends ErrorMap>(
3332
readonly [ScopeField]: symbol;
3433
readonly [PayloadField]: Payload;
3534
readonly [CodeField]: Code;
36-
[MetaField]: Record<string, unknown>;
3735

3836
constructor(
3937
_caller: (...args: Payload) => ErrorUnionOfMap<M>,
@@ -47,15 +45,13 @@ export function That<const M extends ErrorMap>(
4745
this[CodeField] = code;
4846
this[ScopeField] = scope;
4947
this[PayloadField] = args;
50-
this[MetaField] = {};
5148

5249
Error.captureStackTrace(this, _caller);
5350
}
5451

55-
with<Mt extends Record<string, unknown>>(options?: ErrorOptions, meta?: Mt) {
52+
with(options?: ErrorOptions) {
5653
this.cause = options?.cause;
57-
this[MetaField] = {...this[MetaField], ...meta};
58-
return this as DefinedError<Code, Payload, Mt>;
54+
return this;
5955
}
6056

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

packages/core/src/of.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
type DefinedError,
44
type ErrorCase,
55
type ErrorFamily,
6-
MetaField,
76
PayloadField,
87
ScopeField
98
} from "./types";
@@ -31,7 +30,3 @@ export function payloadOf<E extends DefinedError>(error: E): E[typeof PayloadFie
3130
export function codeOf<E extends DefinedError>(error: E): E[typeof CodeField] {
3231
return error[CodeField];
3332
}
34-
35-
export function metaOf<E extends DefinedError>(error: E): Record<string, unknown> {
36-
return error[MetaField] ?? {};
37-
}

packages/core/src/types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@ export const ErrorBrand: unique symbol = Symbol("FErrorBrand");
22
export const ScopeField: unique symbol = Symbol("FErrorScope");
33
export const PayloadField: unique symbol = Symbol("FErrorPayload");
44
export const CodeField: unique symbol = Symbol("FErrorCode");
5-
export const MetaField: unique symbol = Symbol("FErrorMeta");
65

76
export interface DefinedError<
87
Code extends string = string,
98
Payload extends readonly unknown[] = readonly unknown[],
10-
Meta = Record<string, unknown>
119
> extends Error {
1210
readonly [ErrorBrand]: true;
1311
readonly [ScopeField]: symbol;
1412
readonly [PayloadField]: Payload;
1513
readonly [CodeField]: Code;
16-
[MetaField]: Meta;
1714

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

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

0 commit comments

Comments
 (0)