@smithers-orchestrator/errors 0.16.0
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.
- package/LICENSE +21 -0
- package/package.json +33 -0
- package/src/AgentCliError.js +9 -0
- package/src/DbWriteFailed.js +9 -0
- package/src/ERROR_REFERENCE_URL.js +1 -0
- package/src/EngineError.js +17 -0
- package/src/EngineErrorCode.ts +21 -0
- package/src/ErrorWrapOptions.ts +6 -0
- package/src/InvalidInput.js +9 -0
- package/src/KnownSmithersErrorCode.ts +3 -0
- package/src/RunNotFound.js +14 -0
- package/src/SmithersError.js +55 -0
- package/src/SmithersErrorCategory.ts +11 -0
- package/src/SmithersErrorCode.ts +3 -0
- package/src/SmithersErrorDefinition.ts +7 -0
- package/src/SmithersErrorOptions.ts +5 -0
- package/src/SmithersTaggedError.ts +18 -0
- package/src/SmithersTaggedErrorPayload.ts +52 -0
- package/src/SmithersTaggedErrorTag.ts +3 -0
- package/src/TaggedErrorDetails.ts +6 -0
- package/src/TaskAborted.js +17 -0
- package/src/TaskHeartbeatTimeout.js +19 -0
- package/src/TaskTimeout.js +16 -0
- package/src/WorkflowFailed.js +15 -0
- package/src/errorToJson.js +35 -0
- package/src/fromTaggedError.js +63 -0
- package/src/fromTaggedErrorPayload.js +68 -0
- package/src/getSmithersErrorDefinition.js +14 -0
- package/src/getSmithersErrorDocsUrl.js +10 -0
- package/src/index.d.ts +901 -0
- package/src/index.js +40 -0
- package/src/isKnownSmithersErrorCode.js +10 -0
- package/src/isSmithersError.js +12 -0
- package/src/isSmithersTaggedError.js +12 -0
- package/src/isSmithersTaggedErrorTag.js +11 -0
- package/src/knownSmithersErrorCodes.js +7 -0
- package/src/smithersErrorDefinitions.js +382 -0
- package/src/smithersTaggedErrorCodes.js +10 -0
- package/src/tagged.js +24 -0
- package/src/toSmithersError.js +64 -0
- package/src/toTaggedErrorPayload.js +92 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 William Cory
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@smithers-orchestrator/errors",
|
|
3
|
+
"version": "0.16.0",
|
|
4
|
+
"description": "Error types, tagged errors, and error utilities for Smithers",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./src/index.d.ts",
|
|
10
|
+
"import": "./src/index.js",
|
|
11
|
+
"default": "./src/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./*": {
|
|
14
|
+
"types": "./src/index.d.ts",
|
|
15
|
+
"import": "./src/*.js",
|
|
16
|
+
"default": "./src/*.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"src/"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"effect": "^3.21.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/bun": "latest",
|
|
27
|
+
"typescript": "~5.9.3"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
31
|
+
"build": "tsup --dts-only"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
|
|
3
|
+
/** @typedef {import("./TaggedErrorDetails.ts").GenericTaggedErrorArgs} GenericTaggedErrorArgs */
|
|
4
|
+
|
|
5
|
+
const AgentCliErrorBase = /** @type {new (args: GenericTaggedErrorArgs) => import("effect/Cause").YieldableError & { readonly _tag: "AgentCliError" } & Readonly<GenericTaggedErrorArgs>} */ (
|
|
6
|
+
Data.TaggedError("AgentCliError")
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export class AgentCliError extends AgentCliErrorBase {}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
|
|
3
|
+
/** @typedef {import("./TaggedErrorDetails.ts").GenericTaggedErrorArgs} GenericTaggedErrorArgs */
|
|
4
|
+
|
|
5
|
+
const DbWriteFailedBase = /** @type {new (args: GenericTaggedErrorArgs) => import("effect/Cause").YieldableError & { readonly _tag: "DbWriteFailed" } & Readonly<GenericTaggedErrorArgs>} */ (
|
|
6
|
+
Data.TaggedError("DbWriteFailed")
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export class DbWriteFailed extends DbWriteFailedBase {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ERROR_REFERENCE_URL = "https://smithers.sh/reference/errors";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
|
|
3
|
+
/** @typedef {import("./EngineErrorCode.ts").EngineErrorCode} EngineErrorCode */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {{
|
|
7
|
+
* readonly code: EngineErrorCode;
|
|
8
|
+
* readonly message: string;
|
|
9
|
+
* readonly context?: Record<string, unknown>;
|
|
10
|
+
* }} EngineErrorArgs
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const EngineErrorBase = /** @type {new (args: EngineErrorArgs) => import("effect/Cause").YieldableError & { readonly _tag: "EngineError" } & Readonly<EngineErrorArgs>} */ (
|
|
14
|
+
Data.TaggedError("EngineError")
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export class EngineError extends EngineErrorBase {}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type EngineErrorCode =
|
|
2
|
+
| "TASK_HEARTBEAT_TIMEOUT"
|
|
3
|
+
| "DUPLICATE_ID"
|
|
4
|
+
| "NESTED_LOOP"
|
|
5
|
+
| "INVALID_CONTINUATION_STATE"
|
|
6
|
+
| "TASK_ID_REQUIRED"
|
|
7
|
+
| "TASK_MISSING_OUTPUT"
|
|
8
|
+
| "WORKTREE_EMPTY_PATH"
|
|
9
|
+
| "INVALID_INPUT"
|
|
10
|
+
| "WORKFLOW_EXECUTION_FAILED"
|
|
11
|
+
| "TASK_TIMEOUT"
|
|
12
|
+
| "TASK_ABORTED"
|
|
13
|
+
| "MISSING_OUTPUT"
|
|
14
|
+
| "DEP_NOT_SATISFIED"
|
|
15
|
+
| "RUN_CANCELLED"
|
|
16
|
+
| "RUN_NOT_FOUND"
|
|
17
|
+
| "NODE_NOT_FOUND"
|
|
18
|
+
| "STORAGE_ERROR"
|
|
19
|
+
| "SCHEDULER_ERROR"
|
|
20
|
+
| "SESSION_ERROR"
|
|
21
|
+
| "INTERNAL_ERROR";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
|
|
3
|
+
/** @typedef {import("./TaggedErrorDetails.ts").GenericTaggedErrorArgs} GenericTaggedErrorArgs */
|
|
4
|
+
|
|
5
|
+
const InvalidInputBase = /** @type {new (args: GenericTaggedErrorArgs) => import("effect/Cause").YieldableError & { readonly _tag: "InvalidInput" } & Readonly<GenericTaggedErrorArgs>} */ (
|
|
6
|
+
Data.TaggedError("InvalidInput")
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export class InvalidInput extends InvalidInputBase {}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {{
|
|
5
|
+
* readonly message: string;
|
|
6
|
+
* readonly runId: string;
|
|
7
|
+
* }} RunNotFoundArgs
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const RunNotFoundBase = /** @type {new (args: RunNotFoundArgs) => import("effect/Cause").YieldableError & { readonly _tag: "RunNotFound" } & Readonly<RunNotFoundArgs>} */ (
|
|
11
|
+
Data.TaggedError("RunNotFound")
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export class RunNotFound extends RunNotFoundBase {}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { getSmithersErrorDocsUrl } from "./getSmithersErrorDocsUrl.js";
|
|
2
|
+
/** @typedef {import("./SmithersErrorCode.ts").SmithersErrorCode} SmithersErrorCode */
|
|
3
|
+
/** @typedef {import("./SmithersErrorOptions.ts").SmithersErrorOptions} SmithersErrorOptions */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} message
|
|
7
|
+
* @param {string} docsUrl
|
|
8
|
+
* @returns {string}
|
|
9
|
+
*/
|
|
10
|
+
function formatSmithersErrorMessage(message, docsUrl) {
|
|
11
|
+
if (message.includes(docsUrl))
|
|
12
|
+
return message;
|
|
13
|
+
return `${message} See ${docsUrl}`;
|
|
14
|
+
}
|
|
15
|
+
export class SmithersError extends Error {
|
|
16
|
+
/** @type {SmithersErrorCode} */
|
|
17
|
+
code;
|
|
18
|
+
/** @type {string} */
|
|
19
|
+
summary;
|
|
20
|
+
/** @type {string} */
|
|
21
|
+
docsUrl;
|
|
22
|
+
/** @type {Record<string, unknown> | undefined} */
|
|
23
|
+
details;
|
|
24
|
+
/** @type {unknown} */
|
|
25
|
+
cause;
|
|
26
|
+
/** @type {string} */
|
|
27
|
+
name;
|
|
28
|
+
/**
|
|
29
|
+
* @param {SmithersErrorCode} code
|
|
30
|
+
* @param {string} summary
|
|
31
|
+
* @param {Record<string, unknown>} [details]
|
|
32
|
+
* @param {unknown | SmithersErrorOptions} [causeOrOptions]
|
|
33
|
+
*/
|
|
34
|
+
constructor(code, summary, details, causeOrOptions) {
|
|
35
|
+
const docsUrl = getSmithersErrorDocsUrl(code);
|
|
36
|
+
const isOptionsObject = causeOrOptions &&
|
|
37
|
+
typeof causeOrOptions === "object" &&
|
|
38
|
+
(Object.prototype.hasOwnProperty.call(causeOrOptions, "cause") ||
|
|
39
|
+
Object.prototype.hasOwnProperty.call(causeOrOptions, "includeDocsUrl") ||
|
|
40
|
+
Object.prototype.hasOwnProperty.call(causeOrOptions, "name"));
|
|
41
|
+
const options = /** @type {SmithersErrorOptions} */ (isOptionsObject
|
|
42
|
+
? causeOrOptions
|
|
43
|
+
: { cause: causeOrOptions });
|
|
44
|
+
super(options.includeDocsUrl === false
|
|
45
|
+
? summary
|
|
46
|
+
: formatSmithersErrorMessage(summary, docsUrl), { cause: options.cause });
|
|
47
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
48
|
+
this.name = options.name ?? "SmithersError";
|
|
49
|
+
this.code = code;
|
|
50
|
+
this.summary = summary;
|
|
51
|
+
this.docsUrl = docsUrl;
|
|
52
|
+
this.details = details;
|
|
53
|
+
this.cause = options.cause;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TaskAborted } from "./TaskAborted.ts";
|
|
2
|
+
import type { TaskTimeout } from "./TaskTimeout.ts";
|
|
3
|
+
import type { TaskHeartbeatTimeout } from "./TaskHeartbeatTimeout.ts";
|
|
4
|
+
import type { RunNotFound } from "./RunNotFound.ts";
|
|
5
|
+
import type { InvalidInput } from "./InvalidInput.ts";
|
|
6
|
+
import type { DbWriteFailed } from "./DbWriteFailed.ts";
|
|
7
|
+
import type { AgentCliError } from "./AgentCliError.ts";
|
|
8
|
+
import type { WorkflowFailed } from "./WorkflowFailed.ts";
|
|
9
|
+
|
|
10
|
+
export type SmithersTaggedError =
|
|
11
|
+
| TaskAborted
|
|
12
|
+
| TaskTimeout
|
|
13
|
+
| TaskHeartbeatTimeout
|
|
14
|
+
| RunNotFound
|
|
15
|
+
| InvalidInput
|
|
16
|
+
| DbWriteFailed
|
|
17
|
+
| AgentCliError
|
|
18
|
+
| WorkflowFailed;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { TaggedErrorDetails } from "./TaggedErrorDetails.ts";
|
|
2
|
+
|
|
3
|
+
export type SmithersTaggedErrorPayload =
|
|
4
|
+
| {
|
|
5
|
+
readonly _tag: "TaskAborted";
|
|
6
|
+
readonly message: string;
|
|
7
|
+
readonly details?: TaggedErrorDetails;
|
|
8
|
+
readonly name?: string;
|
|
9
|
+
}
|
|
10
|
+
| {
|
|
11
|
+
readonly _tag: "TaskTimeout";
|
|
12
|
+
readonly message: string;
|
|
13
|
+
readonly nodeId: string;
|
|
14
|
+
readonly attempt: number;
|
|
15
|
+
readonly timeoutMs: number;
|
|
16
|
+
}
|
|
17
|
+
| {
|
|
18
|
+
readonly _tag: "TaskHeartbeatTimeout";
|
|
19
|
+
readonly message: string;
|
|
20
|
+
readonly nodeId: string;
|
|
21
|
+
readonly iteration: number;
|
|
22
|
+
readonly attempt: number;
|
|
23
|
+
readonly timeoutMs: number;
|
|
24
|
+
readonly staleForMs: number;
|
|
25
|
+
readonly lastHeartbeatAtMs: number;
|
|
26
|
+
}
|
|
27
|
+
| {
|
|
28
|
+
readonly _tag: "RunNotFound";
|
|
29
|
+
readonly message: string;
|
|
30
|
+
readonly runId: string;
|
|
31
|
+
}
|
|
32
|
+
| {
|
|
33
|
+
readonly _tag: "InvalidInput";
|
|
34
|
+
readonly message: string;
|
|
35
|
+
readonly details?: TaggedErrorDetails;
|
|
36
|
+
}
|
|
37
|
+
| {
|
|
38
|
+
readonly _tag: "DbWriteFailed";
|
|
39
|
+
readonly message: string;
|
|
40
|
+
readonly details?: TaggedErrorDetails;
|
|
41
|
+
}
|
|
42
|
+
| {
|
|
43
|
+
readonly _tag: "AgentCliError";
|
|
44
|
+
readonly message: string;
|
|
45
|
+
readonly details?: TaggedErrorDetails;
|
|
46
|
+
}
|
|
47
|
+
| {
|
|
48
|
+
readonly _tag: "WorkflowFailed";
|
|
49
|
+
readonly message: string;
|
|
50
|
+
readonly details?: TaggedErrorDetails;
|
|
51
|
+
readonly status?: number;
|
|
52
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
|
|
3
|
+
/** @typedef {import("./TaggedErrorDetails.ts").TaggedErrorDetails} TaggedErrorDetails */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {{
|
|
7
|
+
* readonly message: string;
|
|
8
|
+
* readonly details?: TaggedErrorDetails;
|
|
9
|
+
* readonly name?: string;
|
|
10
|
+
* }} TaskAbortedArgs
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const TaskAbortedBase = /** @type {new (args: TaskAbortedArgs) => import("effect/Cause").YieldableError & { readonly _tag: "TaskAborted" } & Readonly<TaskAbortedArgs>} */ (
|
|
14
|
+
Data.TaggedError("TaskAborted")
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export class TaskAborted extends TaskAbortedBase {}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {{
|
|
5
|
+
* readonly message: string;
|
|
6
|
+
* readonly nodeId: string;
|
|
7
|
+
* readonly iteration: number;
|
|
8
|
+
* readonly attempt: number;
|
|
9
|
+
* readonly timeoutMs: number;
|
|
10
|
+
* readonly staleForMs: number;
|
|
11
|
+
* readonly lastHeartbeatAtMs: number;
|
|
12
|
+
* }} TaskHeartbeatTimeoutArgs
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const TaskHeartbeatTimeoutBase = /** @type {new (args: TaskHeartbeatTimeoutArgs) => import("effect/Cause").YieldableError & { readonly _tag: "TaskHeartbeatTimeout" } & Readonly<TaskHeartbeatTimeoutArgs>} */ (
|
|
16
|
+
Data.TaggedError("TaskHeartbeatTimeout")
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export class TaskHeartbeatTimeout extends TaskHeartbeatTimeoutBase {}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {{
|
|
5
|
+
* readonly message: string;
|
|
6
|
+
* readonly nodeId: string;
|
|
7
|
+
* readonly attempt: number;
|
|
8
|
+
* readonly timeoutMs: number;
|
|
9
|
+
* }} TaskTimeoutArgs
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const TaskTimeoutBase = /** @type {new (args: TaskTimeoutArgs) => import("effect/Cause").YieldableError & { readonly _tag: "TaskTimeout" } & Readonly<TaskTimeoutArgs>} */ (
|
|
13
|
+
Data.TaggedError("TaskTimeout")
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export class TaskTimeout extends TaskTimeoutBase {}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
|
|
3
|
+
/** @typedef {import("./TaggedErrorDetails.ts").GenericTaggedErrorArgs} GenericTaggedErrorArgs */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {GenericTaggedErrorArgs & {
|
|
7
|
+
* readonly status?: number;
|
|
8
|
+
* }} WorkflowFailedArgs
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const WorkflowFailedBase = /** @type {new (args: WorkflowFailedArgs) => import("effect/Cause").YieldableError & { readonly _tag: "WorkflowFailed" } & Readonly<WorkflowFailedArgs>} */ (
|
|
12
|
+
Data.TaggedError("WorkflowFailed")
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export class WorkflowFailed extends WorkflowFailedBase {}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { SmithersError } from "./SmithersError.js";
|
|
2
|
+
import { fromTaggedError } from "./fromTaggedError.js";
|
|
3
|
+
/**
|
|
4
|
+
* @param {unknown} error
|
|
5
|
+
* @returns {Record<string, unknown>}
|
|
6
|
+
*/
|
|
7
|
+
export function errorToJson(error) {
|
|
8
|
+
const taggedError = fromTaggedError(error);
|
|
9
|
+
if (taggedError) {
|
|
10
|
+
return errorToJson(taggedError);
|
|
11
|
+
}
|
|
12
|
+
if (error instanceof SmithersError) {
|
|
13
|
+
return {
|
|
14
|
+
name: error.name,
|
|
15
|
+
code: error.code,
|
|
16
|
+
message: error.message,
|
|
17
|
+
stack: error.stack,
|
|
18
|
+
cause: error.cause,
|
|
19
|
+
summary: error.summary,
|
|
20
|
+
docsUrl: error.docsUrl,
|
|
21
|
+
details: error.details,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (error instanceof Error) {
|
|
25
|
+
return {
|
|
26
|
+
name: error.name,
|
|
27
|
+
message: error.message,
|
|
28
|
+
stack: error.stack,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (error && typeof error === "object") {
|
|
32
|
+
return error;
|
|
33
|
+
}
|
|
34
|
+
return { message: String(error) };
|
|
35
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { SmithersError } from "./SmithersError.js";
|
|
2
|
+
/**
|
|
3
|
+
* @param {unknown} value
|
|
4
|
+
* @returns {TaggedErrorPayload | undefined}
|
|
5
|
+
*/
|
|
6
|
+
function objectPayload(value) {
|
|
7
|
+
return value && typeof value === "object"
|
|
8
|
+
? value
|
|
9
|
+
: undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @param {unknown} error
|
|
13
|
+
* @returns {SmithersError | undefined}
|
|
14
|
+
*/
|
|
15
|
+
export function fromTaggedError(error) {
|
|
16
|
+
const payload = objectPayload(error);
|
|
17
|
+
if (!payload || typeof payload._tag !== "string")
|
|
18
|
+
return undefined;
|
|
19
|
+
const message = typeof payload.message === "string" ? payload.message : String(payload._tag);
|
|
20
|
+
const cause = error && typeof error === "object" && "cause" in error
|
|
21
|
+
? error.cause
|
|
22
|
+
: undefined;
|
|
23
|
+
const details = payload.details && typeof payload.details === "object" && !Array.isArray(payload.details)
|
|
24
|
+
? payload.details
|
|
25
|
+
: undefined;
|
|
26
|
+
switch (payload._tag) {
|
|
27
|
+
case "TaskAborted":
|
|
28
|
+
return new SmithersError("TASK_ABORTED", message, details, {
|
|
29
|
+
cause,
|
|
30
|
+
name: typeof payload.name === "string" ? payload.name : undefined,
|
|
31
|
+
});
|
|
32
|
+
case "TaskTimeout":
|
|
33
|
+
return new SmithersError("TASK_TIMEOUT", message, {
|
|
34
|
+
nodeId: payload.nodeId,
|
|
35
|
+
attempt: payload.attempt,
|
|
36
|
+
timeoutMs: payload.timeoutMs,
|
|
37
|
+
}, { cause });
|
|
38
|
+
case "TaskHeartbeatTimeout":
|
|
39
|
+
return new SmithersError("TASK_HEARTBEAT_TIMEOUT", message, {
|
|
40
|
+
nodeId: payload.nodeId,
|
|
41
|
+
iteration: payload.iteration,
|
|
42
|
+
attempt: payload.attempt,
|
|
43
|
+
timeoutMs: payload.timeoutMs,
|
|
44
|
+
staleForMs: payload.staleForMs,
|
|
45
|
+
lastHeartbeatAtMs: payload.lastHeartbeatAtMs,
|
|
46
|
+
}, { cause });
|
|
47
|
+
case "RunNotFound":
|
|
48
|
+
return new SmithersError("RUN_NOT_FOUND", message, { runId: payload.runId }, { cause });
|
|
49
|
+
case "InvalidInput":
|
|
50
|
+
return new SmithersError("INVALID_INPUT", message, details, { cause });
|
|
51
|
+
case "DbWriteFailed":
|
|
52
|
+
return new SmithersError("DB_WRITE_FAILED", message, details, { cause });
|
|
53
|
+
case "AgentCliError":
|
|
54
|
+
return new SmithersError("AGENT_CLI_ERROR", message, details, { cause });
|
|
55
|
+
case "WorkflowFailed":
|
|
56
|
+
return new SmithersError("WORKFLOW_EXECUTION_FAILED", message, {
|
|
57
|
+
...details,
|
|
58
|
+
...(payload.status === undefined ? {} : { status: payload.status }),
|
|
59
|
+
}, { cause });
|
|
60
|
+
default:
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { TaskAborted } from "./TaskAborted.js";
|
|
2
|
+
import { TaskTimeout } from "./TaskTimeout.js";
|
|
3
|
+
import { TaskHeartbeatTimeout } from "./TaskHeartbeatTimeout.js";
|
|
4
|
+
import { RunNotFound } from "./RunNotFound.js";
|
|
5
|
+
import { InvalidInput } from "./InvalidInput.js";
|
|
6
|
+
import { DbWriteFailed } from "./DbWriteFailed.js";
|
|
7
|
+
import { AgentCliError } from "./AgentCliError.js";
|
|
8
|
+
import { WorkflowFailed } from "./WorkflowFailed.js";
|
|
9
|
+
/** @typedef {import("./SmithersTaggedError.ts").SmithersTaggedError} SmithersTaggedError */
|
|
10
|
+
/** @typedef {import("./SmithersTaggedErrorPayload.ts").SmithersTaggedErrorPayload} SmithersTaggedErrorPayload */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {SmithersTaggedErrorPayload} payload
|
|
14
|
+
* @returns {SmithersTaggedError}
|
|
15
|
+
*/
|
|
16
|
+
export function fromTaggedErrorPayload(payload) {
|
|
17
|
+
switch (payload._tag) {
|
|
18
|
+
case "TaskAborted":
|
|
19
|
+
return new TaskAborted({
|
|
20
|
+
message: payload.message,
|
|
21
|
+
details: payload.details,
|
|
22
|
+
name: payload.name,
|
|
23
|
+
});
|
|
24
|
+
case "TaskTimeout":
|
|
25
|
+
return new TaskTimeout({
|
|
26
|
+
message: payload.message,
|
|
27
|
+
nodeId: payload.nodeId,
|
|
28
|
+
attempt: payload.attempt,
|
|
29
|
+
timeoutMs: payload.timeoutMs,
|
|
30
|
+
});
|
|
31
|
+
case "TaskHeartbeatTimeout":
|
|
32
|
+
return new TaskHeartbeatTimeout({
|
|
33
|
+
message: payload.message,
|
|
34
|
+
nodeId: payload.nodeId,
|
|
35
|
+
iteration: payload.iteration,
|
|
36
|
+
attempt: payload.attempt,
|
|
37
|
+
timeoutMs: payload.timeoutMs,
|
|
38
|
+
staleForMs: payload.staleForMs,
|
|
39
|
+
lastHeartbeatAtMs: payload.lastHeartbeatAtMs,
|
|
40
|
+
});
|
|
41
|
+
case "RunNotFound":
|
|
42
|
+
return new RunNotFound({
|
|
43
|
+
message: payload.message,
|
|
44
|
+
runId: payload.runId,
|
|
45
|
+
});
|
|
46
|
+
case "InvalidInput":
|
|
47
|
+
return new InvalidInput({
|
|
48
|
+
message: payload.message,
|
|
49
|
+
details: payload.details,
|
|
50
|
+
});
|
|
51
|
+
case "DbWriteFailed":
|
|
52
|
+
return new DbWriteFailed({
|
|
53
|
+
message: payload.message,
|
|
54
|
+
details: payload.details,
|
|
55
|
+
});
|
|
56
|
+
case "AgentCliError":
|
|
57
|
+
return new AgentCliError({
|
|
58
|
+
message: payload.message,
|
|
59
|
+
details: payload.details,
|
|
60
|
+
});
|
|
61
|
+
case "WorkflowFailed":
|
|
62
|
+
return new WorkflowFailed({
|
|
63
|
+
message: payload.message,
|
|
64
|
+
details: payload.details,
|
|
65
|
+
status: payload.status,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { smithersErrorDefinitions } from "./smithersErrorDefinitions.js";
|
|
2
|
+
import { isKnownSmithersErrorCode } from "./isKnownSmithersErrorCode.js";
|
|
3
|
+
/** @typedef {import("./SmithersErrorCode.ts").SmithersErrorCode} SmithersErrorCode */
|
|
4
|
+
/** @typedef {import("./SmithersErrorDefinition.ts").SmithersErrorDefinition} SmithersErrorDefinition */
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {SmithersErrorCode} code
|
|
8
|
+
* @returns {SmithersErrorDefinition | undefined}
|
|
9
|
+
*/
|
|
10
|
+
export function getSmithersErrorDefinition(code) {
|
|
11
|
+
if (!isKnownSmithersErrorCode(code))
|
|
12
|
+
return undefined;
|
|
13
|
+
return smithersErrorDefinitions[code];
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ERROR_REFERENCE_URL } from "./ERROR_REFERENCE_URL.js";
|
|
2
|
+
/** @typedef {import("./SmithersErrorCode.ts").SmithersErrorCode} SmithersErrorCode */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {SmithersErrorCode} _code
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
export function getSmithersErrorDocsUrl(_code) {
|
|
9
|
+
return ERROR_REFERENCE_URL;
|
|
10
|
+
}
|