@crewhaus/errors 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -69,4 +69,3 @@ export declare class ProviderAuthError extends AdapterError {
69
69
  readonly name = "ProviderAuthError";
70
70
  constructor(providerId: string, message: string, cause?: unknown);
71
71
  }
72
- //# sourceMappingURL=index.d.ts.map
@@ -100,4 +100,3 @@ export class ProviderAuthError extends AdapterError {
100
100
  super(providerId, message, cause);
101
101
  }
102
102
  }
103
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@crewhaus/errors",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "description": "Typed error hierarchy shared across factory layers",
6
- "main": "src/index.ts",
7
- "types": "src/index.ts",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
8
  "exports": {
9
- ".": "./src/index.ts"
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
10
13
  },
11
14
  "scripts": {
12
15
  "test": "bun test src"
@@ -29,5 +32,5 @@
29
32
  "publishConfig": {
30
33
  "access": "public"
31
34
  },
32
- "files": ["src", "README.md", "LICENSE", "NOTICE"]
35
+ "files": ["dist", "README.md", "LICENSE", "NOTICE"]
33
36
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,SAAS,GACjB,YAAY,GACZ,UAAU,GACV,SAAS,GACT,QAAQ,GACR,MAAM,GACN,KAAK,GACL,SAAS,GACT,SAAS,CAAC;AAEd,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,eAAe,GAAG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AG,kBAAkB,CAAC;IAC5C,wMAAwM;IACxM,YAAY,OAAe,EAAE,KAAe;QAC1C,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,YAAa,SAAQ,aAAa;IAC3B,IAAI,GAAW,cAAc,CAAC;IACvC,UAAU,CAAS;IAC5B,YAAY,UAAkB,EAAE,OAAe,EAAE,KAAe;QAC9D,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,YAAY;IAC/B,IAAI,GAAG,mBAAmB,CAAC;IAC7C,wMAAwM;IACxM,YAAY,UAAkB,EAAE,OAAe,EAAE,KAAe;QAC9D,KAAK,CAAC,UAAU,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;CACF"}
package/src/index.test.ts DELETED
@@ -1,152 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import {
3
- AdapterError,
4
- CompilerError,
5
- ConfigError,
6
- CrewhausError,
7
- McpConnectionError,
8
- McpError,
9
- McpProtocolError,
10
- ProviderAuthError,
11
- RuntimeError,
12
- SpecParseError,
13
- } from "./index";
14
-
15
- describe("CrewhausError", () => {
16
- test("extends Error and exposes a code", () => {
17
- const err = new CrewhausError("config", "boom");
18
- expect(err).toBeInstanceOf(Error);
19
- expect(err).toBeInstanceOf(CrewhausError);
20
- expect(err.code).toBe("config");
21
- expect(err.message).toBe("boom");
22
- expect(err.name).toBe("CrewhausError");
23
- });
24
-
25
- test("toJSON serializes message and code", () => {
26
- const err = new CrewhausError("runtime", "oops");
27
- expect(err.toJSON()).toEqual({
28
- name: "CrewhausError",
29
- code: "runtime",
30
- message: "oops",
31
- cause: undefined,
32
- });
33
- });
34
-
35
- test("preserves cause via Error.cause", () => {
36
- const root = new Error("root");
37
- const err = new CompilerError("could not lower", root);
38
- expect(err.cause).toBe(root);
39
- });
40
-
41
- test("toJSON serializes a plain Error cause", () => {
42
- const root = new Error("root");
43
- const err = new CompilerError("compile failed", root);
44
- expect(err.toJSON().cause).toEqual({ name: "Error", message: "root" });
45
- });
46
-
47
- test("toJSON recursively serializes a CrewhausError cause", () => {
48
- const inner = new SpecParseError("bad yaml");
49
- const outer = new CompilerError("compile failed", inner);
50
- expect(outer.toJSON().cause).toEqual({
51
- name: "SpecParseError",
52
- code: "spec_parse",
53
- message: "bad yaml",
54
- cause: undefined,
55
- });
56
- });
57
-
58
- test("toJSON stringifies non-Error causes", () => {
59
- const err = new RuntimeError("x", "string-cause");
60
- expect(err.toJSON().cause).toEqual({ message: "string-cause" });
61
- });
62
- });
63
-
64
- describe("subclasses", () => {
65
- test("each subclass tags itself with the right code", () => {
66
- expect(new SpecParseError("x").code).toBe("spec_parse");
67
- expect(new CompilerError("x").code).toBe("compiler");
68
- expect(new RuntimeError("x").code).toBe("runtime");
69
- expect(new ConfigError("x").code).toBe("config");
70
- expect(new McpError("x").code).toBe("mcp");
71
- expect(new McpConnectionError("x").code).toBe("mcp");
72
- expect(new McpProtocolError("x").code).toBe("mcp");
73
- });
74
-
75
- test("each subclass has a stable name (for instanceof / log filtering)", () => {
76
- expect(new SpecParseError("x").name).toBe("SpecParseError");
77
- expect(new CompilerError("x").name).toBe("CompilerError");
78
- expect(new RuntimeError("x").name).toBe("RuntimeError");
79
- expect(new ConfigError("x").name).toBe("ConfigError");
80
- expect(new McpError("x").name).toBe("McpError");
81
- expect(new McpConnectionError("x").name).toBe("McpConnectionError");
82
- expect(new McpProtocolError("x").name).toBe("McpProtocolError");
83
- });
84
-
85
- test("subclasses are instanceof their parent", () => {
86
- expect(new SpecParseError("x")).toBeInstanceOf(CrewhausError);
87
- expect(new CompilerError("x")).toBeInstanceOf(CrewhausError);
88
- expect(new RuntimeError("x")).toBeInstanceOf(CrewhausError);
89
- expect(new ConfigError("x")).toBeInstanceOf(CrewhausError);
90
- expect(new McpError("x")).toBeInstanceOf(CrewhausError);
91
- expect(new McpConnectionError("x")).toBeInstanceOf(McpError);
92
- expect(new McpProtocolError("x")).toBeInstanceOf(McpError);
93
- });
94
-
95
- test("McpConnectionError serializes via toJSON", () => {
96
- const err = new McpConnectionError("connection lost", new Error("ECONNREFUSED"));
97
- expect(err.toJSON()).toEqual({
98
- name: "McpConnectionError",
99
- code: "mcp",
100
- message: "connection lost",
101
- cause: { name: "Error", message: "ECONNREFUSED" },
102
- });
103
- });
104
- });
105
-
106
- describe("AdapterError", () => {
107
- test("tags itself with the adapter code and captures providerId", () => {
108
- const err = new AdapterError("openai", "request failed");
109
- expect(err).toBeInstanceOf(CrewhausError);
110
- expect(err.code).toBe("adapter");
111
- expect(err.providerId).toBe("openai");
112
- expect(err.message).toBe("request failed");
113
- expect(err.name).toBe("AdapterError");
114
- });
115
-
116
- test("preserves the underlying SDK error via cause", () => {
117
- const sdkErr = new Error("429 rate limited");
118
- const err = new AdapterError("anthropic", "upstream error", sdkErr);
119
- expect(err.cause).toBe(sdkErr);
120
- });
121
-
122
- test("toJSON serializes the cause chain (providerId is not part of the wire shape)", () => {
123
- const err = new AdapterError("anthropic", "stream parse failed", new Error("EOF"));
124
- expect(err.toJSON()).toEqual({
125
- name: "AdapterError",
126
- code: "adapter",
127
- message: "stream parse failed",
128
- cause: { name: "Error", message: "EOF" },
129
- });
130
- });
131
- });
132
-
133
- describe("ProviderAuthError", () => {
134
- test("is an AdapterError with the adapter code and a stable name", () => {
135
- const err = new ProviderAuthError("openai", "missing OPENAI_API_KEY");
136
- expect(err).toBeInstanceOf(AdapterError);
137
- expect(err).toBeInstanceOf(CrewhausError);
138
- expect(err.code).toBe("adapter");
139
- expect(err.providerId).toBe("openai");
140
- expect(err.name).toBe("ProviderAuthError");
141
- });
142
-
143
- test("toJSON reports the ProviderAuthError name", () => {
144
- const err = new ProviderAuthError("anthropic", "invalid credentials");
145
- expect(err.toJSON()).toEqual({
146
- name: "ProviderAuthError",
147
- code: "adapter",
148
- message: "invalid credentials",
149
- cause: undefined,
150
- });
151
- });
152
- });
package/src/index.ts DELETED
@@ -1,129 +0,0 @@
1
- /**
2
- * Typed error hierarchy for factory.
3
- * Catalog F-foundations (`error-types`) — every later layer imports this
4
- * for structured error reporting instead of throwing raw `Error`s.
5
- *
6
- * Each error carries a stable `code` for programmatic dispatch and serializes
7
- * its full cause chain via `toJSON()` for the logging layer.
8
- */
9
-
10
- export type ErrorCode =
11
- | "spec_parse"
12
- | "compiler"
13
- | "runtime"
14
- | "config"
15
- | "tool"
16
- | "mcp"
17
- | "adapter"
18
- | "channel";
19
-
20
- export type SerializedError = {
21
- name: string;
22
- code: ErrorCode;
23
- message: string;
24
- cause?: SerializedError | { name?: string; message: string };
25
- };
26
-
27
- export class CrewhausError extends Error {
28
- override readonly name: string = "CrewhausError";
29
- readonly code: ErrorCode;
30
-
31
- constructor(code: ErrorCode, message: string, cause?: unknown) {
32
- super(message, cause === undefined ? undefined : { cause });
33
- this.code = code;
34
- }
35
-
36
- toJSON(): SerializedError {
37
- return {
38
- name: this.name,
39
- code: this.code,
40
- message: this.message,
41
- cause: serializeCause(this.cause),
42
- };
43
- }
44
- }
45
-
46
- function serializeCause(cause: unknown): SerializedError["cause"] {
47
- if (cause === undefined) return undefined;
48
- if (cause instanceof CrewhausError) return cause.toJSON();
49
- if (cause instanceof Error) return { name: cause.name, message: cause.message };
50
- return { message: String(cause) };
51
- }
52
-
53
- export class SpecParseError extends CrewhausError {
54
- override readonly name = "SpecParseError";
55
- constructor(message: string, cause?: unknown) {
56
- super("spec_parse", message, cause);
57
- }
58
- }
59
-
60
- export class CompilerError extends CrewhausError {
61
- override readonly name = "CompilerError";
62
- constructor(message: string, cause?: unknown) {
63
- super("compiler", message, cause);
64
- }
65
- }
66
-
67
- export class RuntimeError extends CrewhausError {
68
- override readonly name = "RuntimeError";
69
- constructor(message: string, cause?: unknown) {
70
- super("runtime", message, cause);
71
- }
72
- }
73
-
74
- export class ConfigError extends CrewhausError {
75
- override readonly name = "ConfigError";
76
- constructor(message: string, cause?: unknown) {
77
- super("config", message, cause);
78
- }
79
- }
80
-
81
- export class McpError extends CrewhausError {
82
- override readonly name: string = "McpError";
83
- constructor(message: string, cause?: unknown) {
84
- super("mcp", message, cause);
85
- }
86
- }
87
-
88
- export class McpConnectionError extends McpError {
89
- override readonly name = "McpConnectionError";
90
- // biome-ignore lint/complexity/noUselessConstructor: explicit constructor so Bun --coverage counts it as a covered function (field-initializer-only classes can't hit 100% function coverage otherwise)
91
- constructor(message: string, cause?: unknown) {
92
- super(message, cause);
93
- }
94
- }
95
-
96
- export class McpProtocolError extends McpError {
97
- override readonly name = "McpProtocolError";
98
- // biome-ignore lint/complexity/noUselessConstructor: explicit constructor so Bun --coverage counts it as a covered function (field-initializer-only classes can't hit 100% function coverage otherwise)
99
- constructor(message: string, cause?: unknown) {
100
- super(message, cause);
101
- }
102
- }
103
-
104
- /**
105
- * Section 17 — base for all model-provider adapter failures (auth, request
106
- * marshalling, stream parsing, network). Carries `providerId` so callers can
107
- * branch on which adapter raised; `cause` keeps the underlying SDK error
108
- * accessible via `toJSON()` for the trace/log layer.
109
- */
110
- export class AdapterError extends CrewhausError {
111
- override readonly name: string = "AdapterError";
112
- readonly providerId: string;
113
- constructor(providerId: string, message: string, cause?: unknown) {
114
- super("adapter", message, cause);
115
- this.providerId = providerId;
116
- }
117
- }
118
-
119
- /**
120
- * Section 17 — missing or invalid credentials for a model provider. Surfaces
121
- * with a setup hint pointing at the relevant env var.
122
- */
123
- export class ProviderAuthError extends AdapterError {
124
- override readonly name = "ProviderAuthError";
125
- // biome-ignore lint/complexity/noUselessConstructor: explicit constructor so Bun --coverage counts it as a covered function (field-initializer-only classes can't hit 100% function coverage otherwise)
126
- constructor(providerId: string, message: string, cause?: unknown) {
127
- super(providerId, message, cause);
128
- }
129
- }