refactor(errors): unify EkbError hierarchy across domains and structured CLI error classification
This commit is contained in:
1 parent
2b220bc5d9
commit
c15d622ba2
8 files changed
+89
-40
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { NotFoundError, ValidationError } from "../../core/errors.js";
|
||||
import type { WorkflowDetail } from "./types.js";
|
||||
|
||||
export type WorkflowDraftStatus = "clean" | "dirty" | "saving" | "saved" | "failed";
|
||||
@@ -19,9 +20,9 @@ function pathParts(path: string): string[] {
|
||||
.split(".")
|
||||
.map((part) => part.trim())
|
||||
.filter(Boolean);
|
||||
if (!parts.length) throw new Error("工作流配置路径不能为空");
|
||||
if (!parts.length) throw new ValidationError("工作流配置路径不能为空");
|
||||
if (parts.some((part) => !/^[A-Za-z_$][\w$-]*$/.test(part) && !/^\d+$/.test(part))) {
|
||||
throw new Error(`工作流配置路径非法: ${path}`);
|
||||
throw new ValidationError(`工作流配置路径非法: ${path}`);
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
@@ -40,12 +41,12 @@ export function applyWorkflowPathPatch(
|
||||
let cursor: any = patched;
|
||||
for (const part of parts.slice(0, -1)) {
|
||||
if (cursor === null || typeof cursor !== "object" || !(part in cursor)) {
|
||||
throw new Error(`工作流配置路径不存在: ${path}`);
|
||||
throw new NotFoundError(`工作流配置路径不存在: ${path}`);
|
||||
}
|
||||
cursor = cursor[part];
|
||||
}
|
||||
if (cursor === null || typeof cursor !== "object") {
|
||||
throw new Error(`工作流配置路径不可写: ${path}`);
|
||||
throw new ValidationError(`工作流配置路径不可写: ${path}`);
|
||||
}
|
||||
cursor[parts.at(-1)!] = value;
|
||||
return patched as WorkflowDetail;
|
||||
|
||||
Reference in new issue
Block a user