@milaboratories/pl-errors 1.3.13 → 1.4.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"parsed_error.cjs","names":["z"],"sources":["../src/parsed_error.ts"],"sourcesContent":["/**\n * Thrown when MCP or middle layer attempts an operation with a model API version\n * that doesn't match the block's actual version (e.g., V2 operation on a V1 block).\n */\nexport class ModelAPIVersionMismatchError extends Error {\n constructor(\n public readonly blockId: string,\n public readonly expected: number,\n public readonly actual: number,\n ) {\n super(`Model API version mismatch for block ${blockId}: ${expected} !== ${actual}`);\n this.name = \"ModelAPIVersionMismatchError\";\n }\n}\n\n/** Pl Backend throws arbitrary errors, and we're trying to parse them here. */\n\nimport { z } from \"zod\";\nimport type { ResourceId, ResourceType } from \"@milaboratories/pl-client\";\nimport { resourceIdToString, resourceTypeToString } from \"@milaboratories/pl-client\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/** The error that comes from QuickJS. */\nexport class PlQuickJSError extends Error {\n public stack: string;\n public fullMessage: string;\n\n constructor(quickJSError: Error, cause: Error) {\n super(`PlQuickJSError: ${cause.message}`, { cause });\n this.name = \"PlQuickJSError\";\n\n // QuickJS wraps the error with the name and the message,\n // but we need another format.\n let stack = notEmpty(quickJSError.stack);\n stack = stack.replace(quickJSError.message, \"\");\n stack = stack.replace(notEmpty(cause.message), \"\");\n\n this.stack = stack;\n\n const causeMsg =\n \"fullMessage\" in cause && typeof cause.fullMessage === \"string\"\n ? cause.fullMessage\n : cause.message;\n\n this.fullMessage = `PlQuickJSError: ${causeMsg}\nQuickJS stacktrace:\n${this.stack}\n`;\n }\n}\n\n/**\n * A parsed error from the Pl backend.\n * It contains several suberrors, which could be one or different causes of the error.\n */\nexport class PlErrorReport extends Error {\n public readonly fullMessage: string;\n\n constructor(\n /** Full message from the Pl backend. */\n public readonly rawBackendMessage: string,\n\n /** Either CID conflict or a error from controller. */\n public readonly plErrorType: string,\n\n /** Parsed pl backend message that will be futher parsed into suberrors. */\n public readonly plMessage: string,\n\n /** Could be several different errors, the name is from AggregateError. */\n public readonly errors: PlCoreError[],\n\n /** Optional info about a resource where the error happened. */\n public readonly fieldName?: string,\n public readonly resource?: ResourceId,\n public readonly resourceType?: ResourceType,\n ) {\n const errorMessages = errors.map((e) => e.message).join(\"\\n\\n\");\n const errorFullMessages = errors.map((e) => e.fullMessage).join(\"\\n\\n\");\n\n super(`PlErrorReport: ${errorMessages}`);\n this.name = \"PlErrorReport\";\n\n const rt = this.resourceType ? `${resourceTypeToString(this.resourceType)},` : \"\";\n const r = this.resource ? resourceIdToString(this.resource) : \"\";\n const f = this.fieldName ? `/${this.fieldName}` : \"\";\n const errType = this.plErrorType ? `error type: ${this.plErrorType}` : \"\";\n\n this.fullMessage = `PlErrorReport: resource: ${rt} ${r}${f}\n${errType}\n${errorFullMessages}\n`;\n }\n}\n\n/**\n * A suberror of a parsed error.\n */\nexport type PlCoreError = PlInternalError | PlTengoError | PlRunnerError | PlMonetizationError;\n\n/**\n * An general error when we couldn't parse the cause.\n */\nexport class PlInternalError extends Error {\n public readonly fullMessage: string;\n constructor(public readonly message: string) {\n super(message);\n this.name = \"PlInternalError\";\n this.fullMessage = `PlInternalError: ${message}`;\n }\n}\n\n/**\n * Happens when workflow template panics.\n */\nexport class PlTengoError extends Error {\n public readonly fullMessage: string;\n\n constructor(\n public readonly rawBackendMessage: string,\n public readonly templateName: string,\n public readonly tengoMessage: string,\n public readonly tengoStacktrace: string,\n ) {\n const msg = `PlTengoError:\nmessage:\n${tengoMessage}\ntemplate: ${templateName}\ntengo stacktrace:\n${tengoStacktrace}\n`;\n\n super(msg);\n this.name = \"PlTengoError\";\n\n this.fullMessage = `${msg}\nraw message:\n${this.rawBackendMessage}\n`;\n }\n}\n\n/**\n * Happens when a command fails to run.\n */\nexport class PlRunnerError extends Error {\n public readonly fullMessage: string;\n\n constructor(\n public readonly rawBackendMessage: string,\n public readonly commandName: string,\n public readonly exitCode: number,\n public readonly stdout: string,\n public readonly workingDirectory: string,\n ) {\n const msg = `PlRunnerError:\ncommand: ${commandName}\nexit code: ${exitCode}\nworking directory: ${workingDirectory}\nstdout:\n${stdout}`;\n\n super(msg);\n this.name = \"PlRunnerError\";\n this.fullMessage = `\n${msg}\nraw message:\n${this.rawBackendMessage}\n`;\n }\n}\n\n/**\n * Happens when a monetization command fails to run.\n */\nexport class PlMonetizationError extends PlRunnerError {\n public readonly fullMessage: string;\n constructor(\n rawBackendMessage: string,\n commandName: string,\n exitCode: number,\n stdout: string,\n workingDirectory: string,\n ) {\n super(rawBackendMessage, commandName, exitCode, stdout, workingDirectory);\n const msg = `Monetizaiton error:\n${this.stdout}\n`;\n\n this.message = msg;\n this.name = \"PlMonetizationError\";\n\n this.fullMessage = `\n${msg}\ncommand: ${this.commandName}\nexit code: ${this.exitCode}\nworking directory: ${this.workingDirectory}\n\nraw message:\n${this.rawBackendMessage}\n`;\n }\n}\n\n/**\n * How the Pl backend represents an error.\n */\nconst backendErrorSchema = z\n .object({\n errorType: z.string().default(\"\"),\n message: z.string(),\n })\n .passthrough();\n\n/**\n * Parses a Pl error and suberrors from the Pl backend.\n */\nexport function parsePlError(\n error: string,\n resource?: ResourceId,\n resourceType?: ResourceType,\n field?: string,\n): PlErrorReport {\n const parsed = backendErrorSchema.safeParse(JSON.parse(error));\n if (!parsed.success) {\n throw new Error(`parsePlError: failed to parse the message, got ${error}`);\n }\n\n const errors = parseSubErrors(parsed.data.message);\n\n return new PlErrorReport(\n error,\n parsed.data.errorType,\n parsed.data.message,\n errors,\n\n field,\n resource,\n resourceType,\n );\n}\n\n/**\n * Reduces over the lines of the pl error message\n * to extract messages, and categorizes them.\n */\nexport function parseSubErrors(message: string): PlCoreError[] {\n // the state of this reducing function\n const state = {\n stage: \"initial\" as \"initial\" | \"path\" | \"message\",\n value: [] as string[],\n result: [] as PlCoreError[],\n };\n\n for (const line of message.split(\"\\n\")) {\n if (state.stage == \"initial\") {\n // we need initial stage because apparently the first line\n // of the error doesn't have [I], but is a path line.\n state.stage = \"path\";\n } else if (state.stage == \"path\" && line.startsWith(\"---\")) {\n // we should add stack separator to path stage\n // without break stage processing\n } else if (state.stage == \"path\" && !isPath(line)) {\n state.stage = \"message\";\n } else if (state.stage == \"message\" && isPath(line)) {\n state.stage = \"path\";\n const text = state.value.join(\"\\n\");\n state.result.push(parseCoreError(text));\n state.value = [];\n }\n\n state.value.push(line);\n }\n\n const text = state.value.join(\"\\n\");\n state.result.push(parseCoreError(text));\n\n return state.result;\n}\n\nfunction isPath(line: string): boolean {\n for (const fieldType of [\"U\", \"I\", \"O\", \"S\", \"OTW\", \"D\", \"MTW\"]) {\n if (line.startsWith(`[${fieldType}]`)) return true;\n }\n\n return false;\n}\n\n/**\n * Parses a suberror from the Pl backend.\n */\nfunction parseCoreError(message: string): PlCoreError {\n // trying to parse a runner or monetization error.\n // https://regex101.com/r/tmKLj7/1\n const runnerErrorRegex =\n /working directory: \"(.*)\"[\\s\\S]failed to run command: \"([^\"]+)\" exited with code (\\d+)\\.[\\s\\S]*?Here is the latest command output:[\\s\\S]*?\\t([\\s\\S]*)/;\n const match = message.match(runnerErrorRegex);\n if (match) {\n const workingDirectory = match[1];\n const command = match[2];\n const exitCode = parseInt(match[3], 10);\n const stdout = match[4].trim();\n\n if (command.endsWith(`mnz-client`) && exitCode == 1) {\n return new PlMonetizationError(message, command, exitCode, stdout, workingDirectory);\n }\n\n return new PlRunnerError(message, command, exitCode, stdout, workingDirectory);\n }\n\n // trying to parse a Tengo error.\n // https://regex101.com/r/1a7RpO/1\n const workflowErrorRegex =\n /cannot eval code: cannot eval template: template: (.+)\\n\\t(.*?)\\n\\t(at [\\s\\S]*)/;\n const workflowMatch = message.match(workflowErrorRegex);\n if (workflowMatch) {\n const templateName = workflowMatch[1];\n const errorMessage = workflowMatch[2];\n const stackTrace = workflowMatch[3];\n\n return new PlTengoError(message, templateName, errorMessage, stackTrace);\n }\n\n // if we couldn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AM,QAAQ,QAAQ,MADpB,wJAC2C;AAC7C,KAAI,OAAO;EACT,MAAM,mBAAmB,MAAM;EAC/B,MAAM,UAAU,MAAM;EACtB,MAAM,WAAW,SAAS,MAAM,IAAI,GAAG;EACvC,MAAM,SAAS,MAAM,GAAG,MAAM;AAE9B,MAAI,QAAQ,SAAS,aAAa,IAAI,YAAY,EAChD,QAAO,IAAI,oBAAoB,SAAS,SAAS,UAAU,QAAQ,iBAAiB;AAGtF,SAAO,IAAI,cAAc,SAAS,SAAS,UAAU,QAAQ,iBAAiB;;CAOhF,MAAM,gBAAgB,QAAQ,MAD5B,kFACqD;AACvD,KAAI,eAAe;EACjB,MAAM,eAAe,cAAc;EACnC,MAAM,eAAe,cAAc;EACnC,MAAM,aAAa,cAAc;AAEjC,SAAO,IAAI,aAAa,SAAS,cAAc,cAAc,WAAW;;AAI1E,QAAO,IAAI,gBAAgB,QAAQ"}
1
+ {"version":3,"file":"parsed_error.cjs","names":["z"],"sources":["../src/parsed_error.ts"],"sourcesContent":["/**\n * Thrown when MCP or middle layer attempts an operation with a model API version\n * that doesn't match the block's actual version (e.g., V2 operation on a V1 block).\n */\nexport class ModelAPIVersionMismatchError extends Error {\n constructor(\n public readonly blockId: string,\n public readonly expected: number,\n public readonly actual: number,\n ) {\n super(`Model API version mismatch for block ${blockId}: ${expected} !== ${actual}`);\n this.name = \"ModelAPIVersionMismatchError\";\n }\n}\n\n/** Pl Backend throws arbitrary errors, and we're trying to parse them here. */\n\nimport { z } from \"zod\";\nimport type { SignedResourceId, ResourceType } from \"@milaboratories/pl-client\";\nimport { resourceIdToString, resourceTypeToString } from \"@milaboratories/pl-client\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/** The error that comes from QuickJS. */\nexport class PlQuickJSError extends Error {\n public stack: string;\n public fullMessage: string;\n\n constructor(quickJSError: Error, cause: Error) {\n super(`PlQuickJSError: ${cause.message}`, { cause });\n this.name = \"PlQuickJSError\";\n\n // QuickJS wraps the error with the name and the message,\n // but we need another format.\n let stack = notEmpty(quickJSError.stack);\n stack = stack.replace(quickJSError.message, \"\");\n stack = stack.replace(notEmpty(cause.message), \"\");\n\n this.stack = stack;\n\n const causeMsg =\n \"fullMessage\" in cause && typeof cause.fullMessage === \"string\"\n ? cause.fullMessage\n : cause.message;\n\n this.fullMessage = `PlQuickJSError: ${causeMsg}\nQuickJS stacktrace:\n${this.stack}\n`;\n }\n}\n\n/**\n * A parsed error from the Pl backend.\n * It contains several suberrors, which could be one or different causes of the error.\n */\nexport class PlErrorReport extends Error {\n public readonly fullMessage: string;\n\n constructor(\n /** Full message from the Pl backend. */\n public readonly rawBackendMessage: string,\n\n /** Either CID conflict or a error from controller. */\n public readonly plErrorType: string,\n\n /** Parsed pl backend message that will be futher parsed into suberrors. */\n public readonly plMessage: string,\n\n /** Could be several different errors, the name is from AggregateError. */\n public readonly errors: PlCoreError[],\n\n /** Optional info about a resource where the error happened. */\n public readonly fieldName?: string,\n public readonly resource?: SignedResourceId,\n public readonly resourceType?: ResourceType,\n ) {\n const errorMessages = errors.map((e) => e.message).join(\"\\n\\n\");\n const errorFullMessages = errors.map((e) => e.fullMessage).join(\"\\n\\n\");\n\n super(`PlErrorReport: ${errorMessages}`);\n this.name = \"PlErrorReport\";\n\n const rt = this.resourceType ? `${resourceTypeToString(this.resourceType)},` : \"\";\n const r = this.resource ? resourceIdToString(this.resource) : \"\";\n const f = this.fieldName ? `/${this.fieldName}` : \"\";\n const errType = this.plErrorType ? `error type: ${this.plErrorType}` : \"\";\n\n this.fullMessage = `PlErrorReport: resource: ${rt} ${r}${f}\n${errType}\n${errorFullMessages}\n`;\n }\n}\n\n/**\n * A suberror of a parsed error.\n */\nexport type PlCoreError = PlInternalError | PlTengoError | PlRunnerError | PlMonetizationError;\n\n/**\n * An general error when we couldn't parse the cause.\n */\nexport class PlInternalError extends Error {\n public readonly fullMessage: string;\n constructor(public readonly message: string) {\n super(message);\n this.name = \"PlInternalError\";\n this.fullMessage = `PlInternalError: ${message}`;\n }\n}\n\n/**\n * Happens when workflow template panics.\n */\nexport class PlTengoError extends Error {\n public readonly fullMessage: string;\n\n constructor(\n public readonly rawBackendMessage: string,\n public readonly templateName: string,\n public readonly tengoMessage: string,\n public readonly tengoStacktrace: string,\n ) {\n const msg = `PlTengoError:\nmessage:\n${tengoMessage}\ntemplate: ${templateName}\ntengo stacktrace:\n${tengoStacktrace}\n`;\n\n super(msg);\n this.name = \"PlTengoError\";\n\n this.fullMessage = `${msg}\nraw message:\n${this.rawBackendMessage}\n`;\n }\n}\n\n/**\n * Happens when a command fails to run.\n */\nexport class PlRunnerError extends Error {\n public readonly fullMessage: string;\n\n constructor(\n public readonly rawBackendMessage: string,\n public readonly commandName: string,\n public readonly exitCode: number,\n public readonly stdout: string,\n public readonly workingDirectory: string,\n ) {\n const msg = `PlRunnerError:\ncommand: ${commandName}\nexit code: ${exitCode}\nworking directory: ${workingDirectory}\nstdout:\n${stdout}`;\n\n super(msg);\n this.name = \"PlRunnerError\";\n this.fullMessage = `\n${msg}\nraw message:\n${this.rawBackendMessage}\n`;\n }\n}\n\n/**\n * Happens when a monetization command fails to run.\n */\nexport class PlMonetizationError extends PlRunnerError {\n public readonly fullMessage: string;\n constructor(\n rawBackendMessage: string,\n commandName: string,\n exitCode: number,\n stdout: string,\n workingDirectory: string,\n ) {\n super(rawBackendMessage, commandName, exitCode, stdout, workingDirectory);\n const msg = `Monetizaiton error:\n${this.stdout}\n`;\n\n this.message = msg;\n this.name = \"PlMonetizationError\";\n\n this.fullMessage = `\n${msg}\ncommand: ${this.commandName}\nexit code: ${this.exitCode}\nworking directory: ${this.workingDirectory}\n\nraw message:\n${this.rawBackendMessage}\n`;\n }\n}\n\n/**\n * How the Pl backend represents an error.\n */\nconst backendErrorSchema = z\n .object({\n errorType: z.string().default(\"\"),\n message: z.string(),\n })\n .passthrough();\n\n/**\n * Parses a Pl error and suberrors from the Pl backend.\n */\nexport function parsePlError(\n error: string,\n resource?: SignedResourceId,\n resourceType?: ResourceType,\n field?: string,\n): PlErrorReport {\n const parsed = backendErrorSchema.safeParse(JSON.parse(error));\n if (!parsed.success) {\n throw new Error(`parsePlError: failed to parse the message, got ${error}`);\n }\n\n const errors = parseSubErrors(parsed.data.message);\n\n return new PlErrorReport(\n error,\n parsed.data.errorType,\n parsed.data.message,\n errors,\n\n field,\n resource,\n resourceType,\n );\n}\n\n/**\n * Reduces over the lines of the pl error message\n * to extract messages, and categorizes them.\n */\nexport function parseSubErrors(message: string): PlCoreError[] {\n // the state of this reducing function\n const state = {\n stage: \"initial\" as \"initial\" | \"path\" | \"message\",\n value: [] as string[],\n result: [] as PlCoreError[],\n };\n\n for (const line of message.split(\"\\n\")) {\n if (state.stage == \"initial\") {\n // we need initial stage because apparently the first line\n // of the error doesn't have [I], but is a path line.\n state.stage = \"path\";\n } else if (state.stage == \"path\" && line.startsWith(\"---\")) {\n // we should add stack separator to path stage\n // without break stage processing\n } else if (state.stage == \"path\" && !isPath(line)) {\n state.stage = \"message\";\n } else if (state.stage == \"message\" && isPath(line)) {\n state.stage = \"path\";\n const text = state.value.join(\"\\n\");\n state.result.push(parseCoreError(text));\n state.value = [];\n }\n\n state.value.push(line);\n }\n\n const text = state.value.join(\"\\n\");\n state.result.push(parseCoreError(text));\n\n return state.result;\n}\n\nfunction isPath(line: string): boolean {\n for (const fieldType of [\"U\", \"I\", \"O\", \"S\", \"OTW\", \"D\", \"MTW\"]) {\n if (line.startsWith(`[${fieldType}]`)) return true;\n }\n\n return false;\n}\n\n/**\n * Parses a suberror from the Pl backend.\n */\nfunction parseCoreError(message: string): PlCoreError {\n // trying to parse a runner or monetization error.\n // https://regex101.com/r/tmKLj7/1\n const runnerErrorRegex =\n /working directory: \"(.*)\"[\\s\\S]failed to run command: \"([^\"]+)\" exited with code (\\d+)\\.[\\s\\S]*?Here is the latest command output:[\\s\\S]*?\\t([\\s\\S]*)/;\n const match = message.match(runnerErrorRegex);\n if (match) {\n const workingDirectory = match[1];\n const command = match[2];\n const exitCode = parseInt(match[3], 10);\n const stdout = match[4].trim();\n\n if (command.endsWith(`mnz-client`) && exitCode == 1) {\n return new PlMonetizationError(message, command, exitCode, stdout, workingDirectory);\n }\n\n return new PlRunnerError(message, command, exitCode, stdout, workingDirectory);\n }\n\n // trying to parse a Tengo error.\n // https://regex101.com/r/1a7RpO/1\n const workflowErrorRegex =\n /cannot eval code: cannot eval template: template: (.+)\\n\\t(.*?)\\n\\t(at [\\s\\S]*)/;\n const workflowMatch = message.match(workflowErrorRegex);\n if (workflowMatch) {\n const templateName = workflowMatch[1];\n const errorMessage = workflowMatch[2];\n const stackTrace = workflowMatch[3];\n\n return new PlTengoError(message, templateName, errorMessage, stackTrace);\n }\n\n // if we couldn't parse the error, return a general error.\n return new PlInternalError(message);\n}\n"],"mappings":";;;;;;;;;AAIA,IAAa,+BAAb,cAAkD,MAAM;CACtD,YACE,SACA,UACA,QACA;AACA,QAAM,wCAAwC,QAAQ,IAAI,SAAS,OAAO,SAAS;AAJnE,OAAA,UAAA;AACA,OAAA,WAAA;AACA,OAAA,SAAA;AAGhB,OAAK,OAAO;;;;AAYhB,IAAa,iBAAb,cAAoC,MAAM;CACxC;CACA;CAEA,YAAY,cAAqB,OAAc;AAC7C,QAAM,mBAAmB,MAAM,WAAW,EAAE,OAAO,CAAC;AACpD,OAAK,OAAO;EAIZ,IAAI,SAAA,GAAA,2BAAA,UAAiB,aAAa,MAAM;AACxC,UAAQ,MAAM,QAAQ,aAAa,SAAS,GAAG;AAC/C,UAAQ,MAAM,SAAA,GAAA,2BAAA,UAAiB,MAAM,QAAQ,EAAE,GAAG;AAElD,OAAK,QAAQ;AAOb,OAAK,cAAc,mBAJjB,iBAAiB,SAAS,OAAO,MAAM,gBAAgB,WACnD,MAAM,cACN,MAAM,QAEmC;;EAEjD,KAAK,MAAM;;;;;;;;AASb,IAAa,gBAAb,cAAmC,MAAM;CACvC;CAEA,YAEE,mBAGA,aAGA,WAGA,QAGA,WACA,UACA,cACA;EACA,MAAM,g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M,OAAO,MAAM,MAAM,KAAK,KAAK;AACnC,SAAM,OAAO,KAAK,eAAe,KAAK,CAAC;AACvC,SAAM,QAAQ,EAAE;;AAGlB,QAAM,MAAM,KAAK,KAAK;;CAGxB,MAAM,OAAO,MAAM,MAAM,KAAK,KAAK;AACnC,OAAM,OAAO,KAAK,eAAe,KAAK,CAAC;AAEvC,QAAO,MAAM;;AAGf,SAAS,OAAO,MAAuB;AACrC,MAAK,MAAM,aAAa;EAAC;EAAK;EAAK;EAAK;EAAK;EAAO;EAAK;EAAM,CAC7D,KAAI,KAAK,WAAW,IAAI,UAAU,GAAG,CAAE,QAAO;AAGhD,QAAO;;;;;AAMT,SAAS,eAAe,SAA8B;CAKpD,MAAM,QAAQ,QAAQ,MADpB,wJAC2C;AAC7C,KAAI,OAAO;EACT,MAAM,mBAAmB,MAAM;EAC/B,MAAM,UAAU,MAAM;EACtB,MAAM,WAAW,SAAS,MAAM,IAAI,GAAG;EACvC,MAAM,SAAS,MAAM,GAAG,MAAM;AAE9B,MAAI,QAAQ,SAAS,aAAa,IAAI,YAAY,EAChD,QAAO,IAAI,oBAAoB,SAAS,SAAS,UAAU,QAAQ,iBAAiB;AAGtF,SAAO,IAAI,cAAc,SAAS,SAAS,UAAU,QAAQ,iBAAiB;;CAOhF,MAAM,gBAAgB,QAAQ,MAD5B,kFACqD;AACvD,KAAI,eAAe;EACjB,MAAM,eAAe,cAAc;EACnC,MAAM,eAAe,cAAc;EACnC,MAAM,aAAa,cAAc;AAEjC,SAAO,IAAI,aAAa,SAAS,cAAc,cAAc,WAAW;;AAI1E,QAAO,IAAI,gBAAgB,QAAQ"}
@@ -1,4 +1,4 @@
1
- import { ResourceId, ResourceType } from "@milaboratories/pl-client";
1
+ import { ResourceType, SignedResourceId } from "@milaboratories/pl-client";
2
2
 
3
3
  //#region src/parsed_error.d.ts
4
4
  /**
@@ -32,7 +32,7 @@ declare class PlErrorReport extends Error {
32
32
  readonly errors: PlCoreError[];
33
33
  /** Optional info about a resource where the error happened. */
34
34
  readonly fieldName?: string | undefined;
35
- readonly resource?: ResourceId | undefined;
35
+ readonly resource?: SignedResourceId | undefined;
36
36
  readonly resourceType?: ResourceType | undefined;
37
37
  readonly fullMessage: string;
38
38
  constructor(/** Full message from the Pl backend. */
@@ -45,7 +45,7 @@ declare class PlErrorReport extends Error {
45
45
 
46
46
  errors: PlCoreError[], /** Optional info about a resource where the error happened. */
47
47
 
48
- fieldName?: string | undefined, resource?: ResourceId | undefined, resourceType?: ResourceType | undefined);
48
+ fieldName?: string | undefined, resource?: SignedResourceId | undefined, resourceType?: ResourceType | undefined);
49
49
  }
50
50
  /**
51
51
  * A suberror of a parsed error.
@@ -92,7 +92,7 @@ declare class PlMonetizationError extends PlRunnerError {
92
92
  /**
93
93
  * Parses a Pl error and suberrors from the Pl backend.
94
94
  */
95
- declare function parsePlError(error: string, resource?: ResourceId, resourceType?: ResourceType, field?: string): PlErrorReport;
95
+ declare function parsePlError(error: string, resource?: SignedResourceId, resourceType?: ResourceType, field?: string): PlErrorReport;
96
96
  /**
97
97
  * Reduces over the lines of the pl error message
98
98
  * to extract messages, and categorizes them.
@@ -1 +1 @@
1
- {"version":3,"file":"parsed_error.d.ts","names":[],"sources":["../src/parsed_error.ts"],"mappings":";;;;;;AAIA;cAAa,4BAAA,SAAqC,KAAA;EAAA,SAE9B,OAAA;EAAA,SACA,QAAA;EAAA,SACA,MAAA;cAFA,OAAA,UACA,QAAA,UACA,MAAA;AAAA;;cAeP,cAAA,SAAuB,KAAA;EAC3B,KAAA;EACA,WAAA;cAEK,YAAA,EAAc,KAAA,EAAO,KAAA,EAAO,KAAA;AAAA;AAJ1C;;;;AAAA,cAgCa,aAAA,SAAsB,KAAA;EAhCC;EAAA,SAqChB,iBAAA;EArCqB;EAAA,SAwCrB,WAAA;EAvCX;EAAA,SA0CW,SAAA;;WAGA,MAAA,EAAQ,WAAA;EA1Cd;EAAA,SA6CM,SAAA;EAAA,SACA,QAAA,GAAW,UAAA;EAAA,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AAA,CAAe,OAAA,WAAkB,WAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"parsed_error.js","names":[],"sources":["../src/parsed_error.ts"],"sourcesContent":["/**\n * Thrown when MCP or middle layer attempts an operation with a model API version\n * that doesn't match the block's actual version (e.g., V2 operation on a V1 block).\n */\nexport class ModelAPIVersionMismatchError extends Error {\n constructor(\n public readonly blockId: string,\n public readonly expected: number,\n public readonly actual: number,\n ) {\n super(`Model API version mismatch for block ${blockId}: ${expected} !== ${actual}`);\n this.name = \"ModelAPIVersionMismatchError\";\n }\n}\n\n/** Pl Backend throws arbitrary errors, and we're trying to parse them here. */\n\nimport { z } from \"zod\";\nimport type { ResourceId, ResourceType } from \"@milaboratories/pl-client\";\nimport { resourceIdToString, resourceTypeToString } from \"@milaboratories/pl-client\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/** The error that comes from QuickJS. */\nexport class PlQuickJSError extends Error {\n public stack: string;\n public fullMessage: string;\n\n constructor(quickJSError: Error, cause: Error) {\n super(`PlQuickJSError: ${cause.message}`, { cause });\n this.name = \"PlQuickJSError\";\n\n // QuickJS wraps the error with the name and the message,\n // but we need another format.\n let stack = notEmpty(quickJSError.stack);\n stack = stack.replace(quickJSError.message, \"\");\n stack = stack.replace(notEmpty(cause.message), \"\");\n\n this.stack = stack;\n\n const causeMsg =\n \"fullMessage\" in cause && typeof cause.fullMessage === \"string\"\n ? cause.fullMessage\n : cause.message;\n\n this.fullMessage = `PlQuickJSError: ${causeMsg}\nQuickJS stacktrace:\n${this.stack}\n`;\n }\n}\n\n/**\n * A parsed error from the Pl backend.\n * It contains several suberrors, which could be one or different causes of the error.\n */\nexport class PlErrorReport extends Error {\n public readonly fullMessage: string;\n\n constructor(\n /** Full message from the Pl backend. */\n public readonly rawBackendMessage: string,\n\n /** Either CID conflict or a error from controller. */\n public readonly plErrorType: string,\n\n /** Parsed pl backend message that will be futher parsed into suberrors. */\n public readonly plMessage: string,\n\n /** Could be several different errors, the name is from AggregateError. */\n public readonly errors: PlCoreError[],\n\n /** Optional info about a resource where the error happened. */\n public readonly fieldName?: string,\n public readonly resource?: ResourceId,\n public readonly resourceType?: ResourceType,\n ) {\n const errorMessages = errors.map((e) => e.message).join(\"\\n\\n\");\n const errorFullMessages = errors.map((e) => e.fullMessage).join(\"\\n\\n\");\n\n super(`PlErrorReport: ${errorMessages}`);\n this.name = \"PlErrorReport\";\n\n const rt = this.resourceType ? `${resourceTypeToString(this.resourceType)},` : \"\";\n const r = this.resource ? resourceIdToString(this.resource) : \"\";\n const f = this.fieldName ? `/${this.fieldName}` : \"\";\n const errType = this.plErrorType ? `error type: ${this.plErrorType}` : \"\";\n\n this.fullMessage = `PlErrorReport: resource: ${rt} ${r}${f}\n${errType}\n${errorFullMessages}\n`;\n }\n}\n\n/**\n * A suberror of a parsed error.\n */\nexport type PlCoreError = PlInternalError | PlTengoError | PlRunnerError | PlMonetizationError;\n\n/**\n * An general error when we couldn't parse the cause.\n */\nexport class PlInternalError extends Error {\n public readonly fullMessage: string;\n constructor(public readonly message: string) {\n super(message);\n this.name = \"PlInternalError\";\n this.fullMessage = `PlInternalError: ${message}`;\n }\n}\n\n/**\n * Happens when workflow template panics.\n */\nexport class PlTengoError extends Error {\n public readonly fullMessage: string;\n\n constructor(\n public readonly rawBackendMessage: string,\n public readonly templateName: string,\n public readonly tengoMessage: string,\n public readonly tengoStacktrace: string,\n ) {\n const msg = `PlTengoError:\nmessage:\n${tengoMessage}\ntemplate: ${templateName}\ntengo stacktrace:\n${tengoStacktrace}\n`;\n\n super(msg);\n this.name = \"PlTengoError\";\n\n this.fullMessage = `${msg}\nraw message:\n${this.rawBackendMessage}\n`;\n }\n}\n\n/**\n * Happens when a command fails to run.\n */\nexport class PlRunnerError extends Error {\n public readonly fullMessage: string;\n\n constructor(\n public readonly rawBackendMessage: string,\n public readonly commandName: string,\n public readonly exitCode: number,\n public readonly stdout: string,\n public readonly workingDirectory: string,\n ) {\n const msg = `PlRunnerError:\ncommand: ${commandName}\nexit code: ${exitCode}\nworking directory: ${workingDirectory}\nstdout:\n${stdout}`;\n\n super(msg);\n this.name = \"PlRunnerError\";\n this.fullMessage = `\n${msg}\nraw message:\n${this.rawBackendMessage}\n`;\n }\n}\n\n/**\n * Happens when a monetization command fails to run.\n */\nexport class PlMonetizationError extends PlRunnerError {\n public readonly fullMessage: string;\n constructor(\n rawBackendMessage: string,\n commandName: string,\n exitCode: number,\n stdout: string,\n workingDirectory: string,\n ) {\n super(rawBackendMessage, commandName, exitCode, stdout, workingDirectory);\n const msg = `Monetizaiton error:\n${this.stdout}\n`;\n\n this.message = msg;\n this.name = \"PlMonetizationError\";\n\n this.fullMessage = `\n${msg}\ncommand: ${this.commandName}\nexit code: ${this.exitCode}\nworking directory: ${this.workingDirectory}\n\nraw message:\n${this.rawBackendMessage}\n`;\n }\n}\n\n/**\n * How the Pl backend represents an error.\n */\nconst backendErrorSchema = z\n .object({\n errorType: z.string().default(\"\"),\n message: z.string(),\n })\n .passthrough();\n\n/**\n * Parses a Pl error and suberrors from the Pl backend.\n */\nexport function parsePlError(\n error: string,\n resource?: ResourceId,\n resourceType?: ResourceType,\n field?: string,\n): PlErrorReport {\n const parsed = backendErrorSchema.safeParse(JSON.parse(error));\n if (!parsed.success) {\n throw new Error(`parsePlError: failed to parse the message, got ${error}`);\n }\n\n const errors = parseSubErrors(parsed.data.message);\n\n return new PlErrorReport(\n error,\n parsed.data.errorType,\n parsed.data.message,\n errors,\n\n field,\n resource,\n resourceType,\n );\n}\n\n/**\n * Reduces over the lines of the pl error message\n * to extract messages, and categorizes them.\n */\nexport function parseSubErrors(message: string): PlCoreError[] {\n // the state of this reducing function\n const state = {\n stage: \"initial\" as \"initial\" | \"path\" | \"message\",\n value: [] as string[],\n result: [] as PlCoreError[],\n };\n\n for (const line of message.split(\"\\n\")) {\n if (state.stage == \"initial\") {\n // we need initial stage because apparently the first line\n // of the error doesn't have [I], but is a path line.\n state.stage = \"path\";\n } else if (state.stage == \"path\" && line.startsWith(\"---\")) {\n // we should add stack separator to path stage\n // without break stage processing\n } else if (state.stage == \"path\" && !isPath(line)) {\n state.stage = \"message\";\n } else if (state.stage == \"message\" && isPath(line)) {\n state.stage = \"path\";\n const text = state.value.join(\"\\n\");\n state.result.push(parseCoreError(text));\n state.value = [];\n }\n\n state.value.push(line);\n }\n\n const text = state.value.join(\"\\n\");\n state.result.push(parseCoreError(text));\n\n return state.result;\n}\n\nfunction isPath(line: string): boolean {\n for (const fieldType of [\"U\", \"I\", \"O\", \"S\", \"OTW\", \"D\", \"MTW\"]) {\n if (line.startsWith(`[${fieldType}]`)) return true;\n }\n\n return false;\n}\n\n/**\n * Parses a suberror from the Pl backend.\n */\nfunction parseCoreError(message: string): PlCoreError {\n // trying to parse a runner or monetization error.\n // https://regex101.com/r/tmKLj7/1\n const runnerErrorRegex =\n /working directory: \"(.*)\"[\\s\\S]failed to run command: \"([^\"]+)\" exited with code (\\d+)\\.[\\s\\S]*?Here is the latest command output:[\\s\\S]*?\\t([\\s\\S]*)/;\n const match = message.match(runnerErrorRegex);\n if (match) {\n const workingDirectory = match[1];\n const command = match[2];\n const exitCode = parseInt(match[3], 10);\n const stdout = match[4].trim();\n\n if (command.endsWith(`mnz-client`) && exitCode == 1) {\n return new PlMonetizationError(message, command, exitCode, stdout, workingDirectory);\n }\n\n return new PlRunnerError(message, command, exitCode, stdout, workingDirectory);\n }\n\n // trying to parse a Tengo error.\n // https://regex101.com/r/1a7RpO/1\n const workflowErrorRegex =\n /cannot eval code: cannot eval template: template: (.+)\\n\\t(.*?)\\n\\t(at [\\s\\S]*)/;\n const workflowMatch = message.match(workflowErrorRegex);\n if (workflowMatch) {\n const templateName = workflowMatch[1];\n const errorMessage = workflowMatch[2];\n const stackTrace = workflowMatch[3];\n\n return new PlTengoError(message, templateName, errorMessage, stackTrace);\n }\n\n // if we couldn't parse the error, return a general error.\n return new PlInternalError(message);\n}\n"],"mappings":";;;;;;;;;AAIA,IAAa,+BAAb,cAAkD,MAAM;C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AM,GAAG,MAAM;AAE9B,MAAI,QAAQ,SAAS,aAAa,IAAI,YAAY,EAChD,QAAO,IAAI,oBAAoB,SAAS,SAAS,UAAU,QAAQ,iBAAiB;AAGtF,SAAO,IAAI,cAAc,SAAS,SAAS,UAAU,QAAQ,iBAAiB;;CAOhF,MAAM,gBAAgB,QAAQ,MAD5B,kFACqD;AACvD,KAAI,eAAe;EACjB,MAAM,eAAe,cAAc;EACnC,MAAM,eAAe,cAAc;EACnC,MAAM,aAAa,cAAc;AAEjC,SAAO,IAAI,aAAa,SAAS,cAAc,cAAc,WAAW;;AAI1E,QAAO,IAAI,gBAAgB,QAAQ"}
1
+ {"version":3,"file":"parsed_error.js","names":[],"sources":["../src/parsed_error.ts"],"sourcesContent":["/**\n * Thrown when MCP or middle layer attempts an operation with a model API version\n * that doesn't match the block's actual version (e.g., V2 operation on a V1 block).\n */\nexport class ModelAPIVersionMismatchError extends Error {\n constructor(\n public readonly blockId: string,\n public readonly expected: number,\n public readonly actual: number,\n ) {\n super(`Model API version mismatch for block ${blockId}: ${expected} !== ${actual}`);\n this.name = \"ModelAPIVersionMismatchError\";\n }\n}\n\n/** Pl Backend throws arbitrary errors, and we're trying to parse them here. */\n\nimport { z } from \"zod\";\nimport type { SignedResourceId, ResourceType } from \"@milaboratories/pl-client\";\nimport { resourceIdToString, resourceTypeToString } from \"@milaboratories/pl-client\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/** The error that comes from QuickJS. */\nexport class PlQuickJSError extends Error {\n public stack: string;\n public fullMessage: string;\n\n constructor(quickJSError: Error, cause: Error) {\n super(`PlQuickJSError: ${cause.message}`, { cause });\n this.name = \"PlQuickJSError\";\n\n // QuickJS wraps the error with the name and the message,\n // but we need another format.\n let stack = notEmpty(quickJSError.stack);\n stack = stack.replace(quickJSError.message, \"\");\n stack = stack.replace(notEmpty(cause.message), \"\");\n\n this.stack = stack;\n\n const causeMsg =\n \"fullMessage\" in cause && typeof cause.fullMessage === \"string\"\n ? cause.fullMessage\n : cause.message;\n\n this.fullMessage = `PlQuickJSError: ${causeMsg}\nQuickJS stacktrace:\n${this.stack}\n`;\n }\n}\n\n/**\n * A parsed error from the Pl backend.\n * It contains several suberrors, which could be one or different causes of the error.\n */\nexport class PlErrorReport extends Error {\n public readonly fullMessage: string;\n\n constructor(\n /** Full message from the Pl backend. */\n public readonly rawBackendMessage: string,\n\n /** Either CID conflict or a error from controller. */\n public readonly plErrorType: string,\n\n /** Parsed pl backend message that will be futher parsed into suberrors. */\n public readonly plMessage: string,\n\n /** Could be several different errors, the name is from AggregateError. */\n public readonly errors: PlCoreError[],\n\n /** Optional info about a resource where the error happened. */\n public readonly fieldName?: string,\n public readonly resource?: SignedResourceId,\n public readonly resourceType?: ResourceType,\n ) {\n const errorMessages = errors.map((e) => e.message).join(\"\\n\\n\");\n const errorFullMessages = errors.map((e) => e.fullMessage).join(\"\\n\\n\");\n\n super(`PlErrorReport: ${errorMessages}`);\n this.name = \"PlErrorReport\";\n\n const rt = this.resourceType ? `${resourceTypeToString(this.resourceType)},` : \"\";\n const r = this.resource ? resourceIdToString(this.resource) : \"\";\n const f = this.fieldName ? `/${this.fieldName}` : \"\";\n const errType = this.plErrorType ? `error type: ${this.plErrorType}` : \"\";\n\n this.fullMessage = `PlErrorReport: resource: ${rt} ${r}${f}\n${errType}\n${errorFullMessages}\n`;\n }\n}\n\n/**\n * A suberror of a parsed error.\n */\nexport type PlCoreError = PlInternalError | PlTengoError | PlRunnerError | PlMonetizationError;\n\n/**\n * An general error when we couldn't parse the cause.\n */\nexport class PlInternalError extends Error {\n public readonly fullMessage: string;\n constructor(public readonly message: string) {\n super(message);\n this.name = \"PlInternalError\";\n this.fullMessage = `PlInternalError: ${message}`;\n }\n}\n\n/**\n * Happens when workflow template panics.\n */\nexport class PlTengoError extends Error {\n public readonly fullMessage: string;\n\n constructor(\n public readonly rawBackendMessage: string,\n public readonly templateName: string,\n public readonly tengoMessage: string,\n public readonly tengoStacktrace: string,\n ) {\n const msg = `PlTengoError:\nmessage:\n${tengoMessage}\ntemplate: ${templateName}\ntengo stacktrace:\n${tengoStacktrace}\n`;\n\n super(msg);\n this.name = \"PlTengoError\";\n\n this.fullMessage = `${msg}\nraw message:\n${this.rawBackendMessage}\n`;\n }\n}\n\n/**\n * Happens when a command fails to run.\n */\nexport class PlRunnerError extends Error {\n public readonly fullMessage: string;\n\n constructor(\n public readonly rawBackendMessage: string,\n public readonly commandName: string,\n public readonly exitCode: number,\n public readonly stdout: string,\n public readonly workingDirectory: string,\n ) {\n const msg = `PlRunnerError:\ncommand: ${commandName}\nexit code: ${exitCode}\nworking directory: ${workingDirectory}\nstdout:\n${stdout}`;\n\n super(msg);\n this.name = \"PlRunnerError\";\n this.fullMessage = `\n${msg}\nraw message:\n${this.rawBackendMessage}\n`;\n }\n}\n\n/**\n * Happens when a monetization command fails to run.\n */\nexport class PlMonetizationError extends PlRunnerError {\n public readonly fullMessage: string;\n constructor(\n rawBackendMessage: string,\n commandName: string,\n exitCode: number,\n stdout: string,\n workingDirectory: string,\n ) {\n super(rawBackendMessage, commandName, exitCode, stdout, workingDirectory);\n const msg = `Monetizaiton error:\n${this.stdout}\n`;\n\n this.message = msg;\n this.name = \"PlMonetizationError\";\n\n this.fullMessage = `\n${msg}\ncommand: ${this.commandName}\nexit code: ${this.exitCode}\nworking directory: ${this.workingDirectory}\n\nraw message:\n${this.rawBackendMessage}\n`;\n }\n}\n\n/**\n * How the Pl backend represents an error.\n */\nconst backendErrorSchema = z\n .object({\n errorType: z.string().default(\"\"),\n message: z.string(),\n })\n .passthrough();\n\n/**\n * Parses a Pl error and suberrors from the Pl backend.\n */\nexport function parsePlError(\n error: string,\n resource?: SignedResourceId,\n resourceType?: ResourceType,\n field?: string,\n): PlErrorReport {\n const parsed = backendErrorSchema.safeParse(JSON.parse(error));\n if (!parsed.success) {\n throw new Error(`parsePlError: failed to parse the message, got ${error}`);\n }\n\n const errors = parseSubErrors(parsed.data.message);\n\n return new PlErrorReport(\n error,\n parsed.data.errorType,\n parsed.data.message,\n errors,\n\n field,\n resource,\n resourceType,\n );\n}\n\n/**\n * Reduces over the lines of the pl error message\n * to extract messages, and categorizes them.\n */\nexport function parseSubErrors(message: string): PlCoreError[] {\n // the state of this reducing function\n const state = {\n stage: \"initial\" as \"initial\" | \"path\" | \"message\",\n value: [] as string[],\n result: [] as PlCoreError[],\n };\n\n for (const line of message.split(\"\\n\")) {\n if (state.stage == \"initial\") {\n // we need initial stage because apparently the first line\n // of the error doesn't have [I], but is a path line.\n state.stage = \"path\";\n } else if (state.stage == \"path\" && line.startsWith(\"---\")) {\n // we should add stack separator to path stage\n // without break stage processing\n } else if (state.stage == \"path\" && !isPath(line)) {\n state.stage = \"message\";\n } else if (state.stage == \"message\" && isPath(line)) {\n state.stage = \"path\";\n const text = state.value.join(\"\\n\");\n state.result.push(parseCoreError(text));\n state.value = [];\n }\n\n state.value.push(line);\n }\n\n const text = state.value.join(\"\\n\");\n state.result.push(parseCoreError(text));\n\n return state.result;\n}\n\nfunction isPath(line: string): boolean {\n for (const fieldType of [\"U\", \"I\", \"O\", \"S\", \"OTW\", \"D\", \"MTW\"]) {\n if (line.startsWith(`[${fieldType}]`)) return true;\n }\n\n return false;\n}\n\n/**\n * Parses a suberror from the Pl backend.\n */\nfunction parseCoreError(message: string): PlCoreError {\n // trying to parse a runner or monetization error.\n // https://regex101.com/r/tmKLj7/1\n const runnerErrorRegex =\n /working directory: \"(.*)\"[\\s\\S]failed to run command: \"([^\"]+)\" exited with code (\\d+)\\.[\\s\\S]*?Here is the latest command output:[\\s\\S]*?\\t([\\s\\S]*)/;\n const match = message.match(runnerErrorRegex);\n if (match) {\n const workingDirectory = match[1];\n const command = match[2];\n const exitCode = parseInt(match[3], 10);\n const stdout = match[4].trim();\n\n if (command.endsWith(`mnz-client`) && exitCode == 1) {\n return new PlMonetizationError(message, command, exitCode, stdout, workingDirectory);\n }\n\n return new PlRunnerError(message, command, exitCode, stdout, workingDirectory);\n }\n\n // trying to parse a Tengo error.\n // https://regex101.com/r/1a7RpO/1\n const workflowErrorRegex =\n /cannot eval code: cannot eval template: template: (.+)\\n\\t(.*?)\\n\\t(at [\\s\\S]*)/;\n const workflowMatch = message.match(workflowErrorRegex);\n if (workflowMatch) {\n const templateName = workflowMatch[1];\n const errorMessage = workflowMatch[2];\n const stackTrace = workflowMatch[3];\n\n return new PlTengoError(message, templateName, errorMessage, stackTrace);\n }\n\n // if we couldn't parse the error, return a general error.\n return new PlInternalError(message);\n}\n"],"mappings":";;;;;;;;;AAIA,IAAa,+BAAb,cAAkD,MAAM;CACtD,YACE,SACA,UACA,QACA;AACA,QAAM,wCAAwC,QAAQ,IAAI,SAAS,OAAO,SAAS;AAJnE,OAAA,UAAA;AACA,OAAA,WAAA;AACA,OAAA,SAAA;AAGhB,OAAK,OAAO;;;;AAYhB,IAAa,iBAAb,cAAoC,MAAM;CACxC;CACA;CAEA,YAAY,cAAqB,OAAc;AAC7C,QAAM,mBAAmB,MAAM,WAAW,EAAE,OAAO,CAAC;AACpD,OAAK,OAAO;EAIZ,IAAI,QAAQ,SAAS,aAAa,MAAM;AACxC,UAAQ,MAAM,QAAQ,aAAa,SAAS,GAAG;AAC/C,UAAQ,MAAM,QAAQ,SAAS,MAAM,QAAQ,EAAE,GAAG;AAElD,OAAK,QAAQ;AAOb,OAAK,cAAc,mBAJjB,iBAAiB,SAAS,OAAO,MAAM,gBAAgB,WACnD,MAAM,cACN,MAAM,QAEmC;;EAEjD,KAAK,MAAM;;;;;;;;AASb,IAAa,gBAAb,cAAmC,MAAM;CACvC;CAEA,YAEE,mBAGA,aAGA,WAGA,QAGA,WACA,UACA,cACA;EACA,MAAM,gBAAgB,OAAO,KAAK,MAAM,EAAE,QAAQ,CAAC,KAAK,OAAO;EAC/D,MAAM,oBAAoB,OAAO,KAAK,MAAM,EAAE,YAAY,CAAC,KAAK,OAAO;AAEvE,QAAM,kBAAkB,gBAAgB;AAnBxB,OAAA,oBAAA;AAGA,OAAA,cAAA;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AAS,OAAO,MAAuB;AACrC,MAAK,MAAM,aAAa;EAAC;EAAK;EAAK;EAAK;EAAK;EAAO;EAAK;EAAM,CAC7D,KAAI,KAAK,WAAW,IAAI,UAAU,GAAG,CAAE,QAAO;AAGhD,QAAO;;;;;AAMT,SAAS,eAAe,SAA8B;CAKpD,MAAM,QAAQ,QAAQ,MADpB,wJAC2C;AAC7C,KAAI,OAAO;EACT,MAAM,mBAAmB,MAAM;EAC/B,MAAM,UAAU,MAAM;EACtB,MAAM,WAAW,SAAS,MAAM,IAAI,GAAG;EACvC,MAAM,SAAS,MAAM,GAAG,MAAM;AAE9B,MAAI,QAAQ,SAAS,aAAa,IAAI,YAAY,EAChD,QAAO,IAAI,oBAAoB,SAAS,SAAS,UAAU,QAAQ,iBAAiB;AAGtF,SAAO,IAAI,cAAc,SAAS,SAAS,UAAU,QAAQ,iBAAiB;;CAOhF,MAAM,gBAAgB,QAAQ,MAD5B,kFACqD;AACvD,KAAI,eAAe;EACjB,MAAM,eAAe,cAAc;EACnC,MAAM,eAAe,cAAc;EACnC,MAAM,aAAa,cAAc;AAEjC,SAAO,IAAI,aAAa,SAAS,cAAc,cAAc,WAAW;;AAI1E,QAAO,IAAI,gBAAgB,QAAQ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milaboratories/pl-errors",
3
- "version": "1.3.13",
3
+ "version": "1.4.1",
4
4
  "description": "Parsing errors from Pl backend",
5
5
  "files": [
6
6
  "./dist/**/*",
@@ -19,16 +19,16 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "zod": "~3.25.76",
22
- "@milaboratories/pl-client": "3.2.5",
23
- "@milaboratories/ts-helpers": "1.8.1"
22
+ "@milaboratories/ts-helpers": "1.8.1",
23
+ "@milaboratories/pl-client": "3.3.1"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@vitest/coverage-istanbul": "^4.1.3",
27
27
  "typescript": "~5.9.3",
28
28
  "vitest": "^4.1.3",
29
29
  "@milaboratories/build-configs": "2.0.0",
30
+ "@milaboratories/ts-builder": "1.4.0",
30
31
  "@milaboratories/pl-error-like": "1.12.10",
31
- "@milaboratories/ts-builder": "1.3.2",
32
32
  "@milaboratories/ts-configs": "1.2.3"
33
33
  },
34
34
  "scripts": {
@@ -16,7 +16,7 @@ export class ModelAPIVersionMismatchError extends Error {
16
16
  /** Pl Backend throws arbitrary errors, and we're trying to parse them here. */
17
17
 
18
18
  import { z } from "zod";
19
- import type { ResourceId, ResourceType } from "@milaboratories/pl-client";
19
+ import type { SignedResourceId, ResourceType } from "@milaboratories/pl-client";
20
20
  import { resourceIdToString, resourceTypeToString } from "@milaboratories/pl-client";
21
21
  import { notEmpty } from "@milaboratories/ts-helpers";
22
22
 
@@ -71,7 +71,7 @@ export class PlErrorReport extends Error {
71
71
 
72
72
  /** Optional info about a resource where the error happened. */
73
73
  public readonly fieldName?: string,
74
- public readonly resource?: ResourceId,
74
+ public readonly resource?: SignedResourceId,
75
75
  public readonly resourceType?: ResourceType,
76
76
  ) {
77
77
  const errorMessages = errors.map((e) => e.message).join("\n\n");
@@ -216,7 +216,7 @@ const backendErrorSchema = z
216
216
  */
217
217
  export function parsePlError(
218
218
  error: string,
219
- resource?: ResourceId,
219
+ resource?: SignedResourceId,
220
220
  resourceType?: ResourceType,
221
221
  field?: string,
222
222
  ): PlErrorReport {