@milaboratories/pl-errors 1.1.14 → 1.1.16

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/dist/index.cjs ADDED
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ var parsed_error = require('./parsed_error.cjs');
4
+
5
+
6
+
7
+ exports.PlErrorReport = parsed_error.PlErrorReport;
8
+ exports.PlInternalError = parsed_error.PlInternalError;
9
+ exports.PlMonetizationError = parsed_error.PlMonetizationError;
10
+ exports.PlQuickJSError = parsed_error.PlQuickJSError;
11
+ exports.PlRunnerError = parsed_error.PlRunnerError;
12
+ exports.PlTengoError = parsed_error.PlTengoError;
13
+ exports.parsePlError = parsed_error.parsePlError;
14
+ exports.parseSubErrors = parsed_error.parseSubErrors;
15
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  export * from './parsed_error';
2
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,43 +1,2 @@
1
- "use strict";var z=Object.defineProperty;var v=(t,e,r)=>e in t?z(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var l=(t,e,r)=>v(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("zod"),p=require("@milaboratories/pl-client"),m=require("@milaboratories/ts-helpers");class I extends Error{constructor(r,o){super(`PlQuickJSError: ${o.message}`,{cause:o});l(this,"stack");l(this,"fullMessage");this.name="PlQuickJSError";let s=m.notEmpty(r.stack);s=s.replace(r.message,""),s=s.replace(m.notEmpty(o.message),""),this.stack=s;const n="fullMessage"in o&&typeof o.fullMessage=="string"?o.fullMessage:o.message;this.fullMessage=`PlQuickJSError: ${n}
2
- QuickJS stacktrace:
3
- ${this.stack}
4
- `}}class E extends Error{constructor(r,o,s,n,a,i,c){const w=n.map(u=>u.message).join(`
5
-
6
- `),y=n.map(u=>u.fullMessage).join(`
7
-
8
- `);super(`PlErrorReport: ${w}`);l(this,"fullMessage");this.rawBackendMessage=r,this.plErrorType=o,this.plMessage=s,this.errors=n,this.fieldName=a,this.resource=i,this.resourceType=c,this.name="PlErrorReport";const T=this.resourceType?`${p.resourceTypeToString(this.resourceType)},`:"",S=this.resource?p.resourceIdToString(this.resource):"",x=this.fieldName?`/${this.fieldName}`:"",R=this.plErrorType?`error type: ${this.plErrorType}`:"";this.fullMessage=`PlErrorReport: resource: ${T} ${S}${x}
9
- ${R}
10
- ${y}
11
- `}}class M extends Error{constructor(r){super(r);l(this,"fullMessage");this.message=r,this.name="PlInternalError",this.fullMessage=`PlInternalError: ${r}`}}class $ extends Error{constructor(r,o,s,n){const a=`PlTengoError:
12
- message:
13
- ${s}
14
- template: ${o}
15
- tengo stacktrace:
16
- ${n}
17
- `;super(a);l(this,"fullMessage");this.rawBackendMessage=r,this.templateName=o,this.tengoMessage=s,this.tengoStacktrace=n,this.name="PlTengoError",this.fullMessage=`${a}
18
- raw message:
19
- ${this.rawBackendMessage}
20
- `}}class h extends Error{constructor(r,o,s,n,a){const i=`PlRunnerError:
21
- command: ${o}
22
- exit code: ${s}
23
- working directory: ${a}
24
- stdout:
25
- ${n}`;super(i);l(this,"fullMessage");this.rawBackendMessage=r,this.commandName=o,this.exitCode=s,this.stdout=n,this.workingDirectory=a,this.name="PlRunnerError",this.fullMessage=`
26
- ${i}
27
- raw message:
28
- ${this.rawBackendMessage}
29
- `}}class P extends h{constructor(r,o,s,n,a){super(r,o,s,n,a);l(this,"fullMessage");const i=`Monetizaiton error:
30
- ${this.stdout}
31
- `;this.message=i,this.name="PlMonetizationError",this.fullMessage=`
32
- ${i}
33
- command: ${this.commandName}
34
- exit code: ${this.exitCode}
35
- working directory: ${this.workingDirectory}
36
-
37
- raw message:
38
- ${this.rawBackendMessage}
39
- `}}const b=g.z.object({errorType:g.z.string().default(""),message:g.z.string()});function j(t,e,r,o){const s=b.safeParse(JSON.parse(t));if(!s.success)throw new Error(`parsePlError: failed to parse the message, got ${t}`);const n=k(s.data.message);return new E(t,s.data.errorType,s.data.message,n,o,e,r)}function k(t){const e={stage:"initial",value:[],result:[]};for(const o of t.split(`
40
- `)){if(e.stage=="initial")e.stage="path";else if(!(e.stage=="path"&&o.startsWith("---"))){if(e.stage=="path"&&!d(o))e.stage="message";else if(e.stage=="message"&&d(o)){e.stage="path";const s=e.value.join(`
41
- `);e.result.push(f(s)),e.value=[]}}e.value.push(o)}const r=e.value.join(`
42
- `);return e.result.push(f(r)),e.result}function d(t){for(const e of["U","I","O","S","OTW","D","MTW"])if(t.startsWith(`[${e}]`))return!0;return!1}function f(t){const e=/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]*)/,r=t.match(e);if(r){const n=r[1],a=r[2],i=parseInt(r[3],10),c=r[4].trim();return a.endsWith("mnz-client")&&i==1?new P(t,a,i,c,n):new h(t,a,i,c,n)}const o=/cannot eval code: cannot eval template: template: (.+)\n\t(.*?)\n\t(at [\s\S]*)/,s=t.match(o);if(s){const n=s[1],a=s[2],i=s[3];return new $(t,n,a,i)}return new M(t)}exports.PlErrorReport=E;exports.PlInternalError=M;exports.PlMonetizationError=P;exports.PlQuickJSError=I;exports.PlRunnerError=h;exports.PlTengoError=$;exports.parsePlError=j;exports.parseSubErrors=k;
1
+ export { PlErrorReport, PlInternalError, PlMonetizationError, PlQuickJSError, PlRunnerError, PlTengoError, parsePlError, parseSubErrors } from './parsed_error.js';
43
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/parsed_error.ts"],"sourcesContent":["/** 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(\n quickJSError: Error,\n cause: Error,\n ) {\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 = '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 =\n | PlInternalError\n | PlTengoError\n | PlRunnerError\n | 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(\n public readonly message: string,\n ) {\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.object({\n errorType: z.string().default(''),\n message: z.string(),\n});\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}]`))\n 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 = /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 = /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"],"names":["PlQuickJSError","quickJSError","cause","__publicField","stack","notEmpty","causeMsg","PlErrorReport","rawBackendMessage","plErrorType","plMessage","errors","fieldName","resource","resourceType","errorMessages","e","errorFullMessages","rt","resourceTypeToString","r","resourceIdToString","f","errType","PlInternalError","message","PlTengoError","templateName","tengoMessage","tengoStacktrace","msg","PlRunnerError","commandName","exitCode","stdout","workingDirectory","PlMonetizationError","backendErrorSchema","z","parsePlError","error","field","parsed","parseSubErrors","state","line","isPath","text","parseCoreError","fieldType","runnerErrorRegex","match","command","workflowErrorRegex","workflowMatch","errorMessage","stackTrace"],"mappings":"0VAQO,MAAMA,UAAuB,KAAM,CAIxC,YACEC,EACAC,EACA,CACA,MAAM,mBAAmBA,EAAM,OAAO,GAAI,CAAE,MAAAA,EAAO,EAP9CC,EAAA,cACAA,EAAA,oBAOL,KAAK,KAAO,iBAIR,IAAAC,EAAQC,EAAAA,SA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GAAIJ,EAAK,WAAW,IAAII,CAAS,GAAG,EAC3B,MAAA,GAGJ,MAAA,EACT,CAKA,SAASD,EAAevB,EAA8B,CAGpD,MAAMyB,EAAmB,wJACnBC,EAAQ1B,EAAQ,MAAMyB,CAAgB,EAC5C,GAAIC,EAAO,CACH,MAAAhB,EAAmBgB,EAAM,CAAC,EAC1BC,EAAUD,EAAM,CAAC,EACjBlB,EAAW,SAASkB,EAAM,CAAC,EAAG,EAAE,EAChCjB,EAASiB,EAAM,CAAC,EAAE,KAAK,EAE7B,OAAIC,EAAQ,SAAS,YAAY,GAAKnB,GAAY,EACzC,IAAIG,EAAoBX,EAAS2B,EAASnB,EAAUC,EAAQC,CAAgB,EAG9E,IAAIJ,EAAcN,EAAS2B,EAASnB,EAAUC,EAAQC,CAAgB,CAAA,CAK/E,MAAMkB,EAAqB,kFACrBC,EAAgB7B,EAAQ,MAAM4B,CAAkB,EACtD,GAAIC,EAAe,CACX,MAAA3B,EAAe2B,EAAc,CAAC,EAC9BC,EAAeD,EAAc,CAAC,EAC9BE,EAAaF,EAAc,CAAC,EAElC,OAAO,IAAI5B,EAAaD,EAASE,EAAc4B,EAAcC,CAAU,CAAA,CAIlE,OAAA,IAAIhC,EAAgBC,CAAO,CACpC"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,269 @@
1
+ 'use strict';
2
+
3
+ var zod = require('zod');
4
+ var plClient = require('@milaboratories/pl-client');
5
+ var tsHelpers = require('@milaboratories/ts-helpers');
6
+
7
+ /** Pl Backend throws arbitrary errors, and we're trying to parse them here. */
8
+ /** The error that comes from QuickJS. */
9
+ class PlQuickJSError extends Error {
10
+ stack;
11
+ fullMessage;
12
+ constructor(quickJSError, cause) {
13
+ super(`PlQuickJSError: ${cause.message}`, { cause });
14
+ this.name = 'PlQuickJSError';
15
+ // QuickJS wraps the error with the name and the message,
16
+ // but we need another format.
17
+ let stack = tsHelpers.notEmpty(quickJSError.stack);
18
+ stack = stack.replace(quickJSError.message, '');
19
+ stack = stack.replace(tsHelpers.notEmpty(cause.message), '');
20
+ this.stack = stack;
21
+ const causeMsg = 'fullMessage' in cause && typeof cause.fullMessage === 'string'
22
+ ? cause.fullMessage
23
+ : cause.message;
24
+ this.fullMessage = `PlQuickJSError: ${causeMsg}
25
+ QuickJS stacktrace:
26
+ ${this.stack}
27
+ `;
28
+ }
29
+ }
30
+ /**
31
+ * A parsed error from the Pl backend.
32
+ * It contains several suberrors, which could be one or different causes of the error.
33
+ */
34
+ class PlErrorReport extends Error {
35
+ rawBackendMessage;
36
+ plErrorType;
37
+ plMessage;
38
+ errors;
39
+ fieldName;
40
+ resource;
41
+ resourceType;
42
+ fullMessage;
43
+ constructor(
44
+ /** Full message from the Pl backend. */
45
+ rawBackendMessage,
46
+ /** Either CID conflict or a error from controller. */
47
+ plErrorType,
48
+ /** Parsed pl backend message that will be futher parsed into suberrors. */
49
+ plMessage,
50
+ /** Could be several different errors, the name is from AggregateError. */
51
+ errors,
52
+ /** Optional info about a resource where the error happened. */
53
+ fieldName, resource, resourceType) {
54
+ const errorMessages = errors.map((e) => e.message).join('\n\n');
55
+ const errorFullMessages = errors.map((e) => e.fullMessage).join('\n\n');
56
+ super(`PlErrorReport: ${errorMessages}`);
57
+ this.rawBackendMessage = rawBackendMessage;
58
+ this.plErrorType = plErrorType;
59
+ this.plMessage = plMessage;
60
+ this.errors = errors;
61
+ this.fieldName = fieldName;
62
+ this.resource = resource;
63
+ this.resourceType = resourceType;
64
+ this.name = 'PlErrorReport';
65
+ const rt = this.resourceType ? `${plClient.resourceTypeToString(this.resourceType)},` : '';
66
+ const r = this.resource ? plClient.resourceIdToString(this.resource) : '';
67
+ const f = this.fieldName ? `/${this.fieldName}` : '';
68
+ const errType = this.plErrorType ? `error type: ${this.plErrorType}` : '';
69
+ this.fullMessage = `PlErrorReport: resource: ${rt} ${r}${f}
70
+ ${errType}
71
+ ${errorFullMessages}
72
+ `;
73
+ }
74
+ }
75
+ /**
76
+ * An general error when we couldn't parse the cause.
77
+ */
78
+ class PlInternalError extends Error {
79
+ message;
80
+ fullMessage;
81
+ constructor(message) {
82
+ super(message);
83
+ this.message = message;
84
+ this.name = 'PlInternalError';
85
+ this.fullMessage = `PlInternalError: ${message}`;
86
+ }
87
+ }
88
+ /**
89
+ * Happens when workflow template panics.
90
+ */
91
+ class PlTengoError extends Error {
92
+ rawBackendMessage;
93
+ templateName;
94
+ tengoMessage;
95
+ tengoStacktrace;
96
+ fullMessage;
97
+ constructor(rawBackendMessage, templateName, tengoMessage, tengoStacktrace) {
98
+ const msg = `PlTengoError:
99
+ message:
100
+ ${tengoMessage}
101
+ template: ${templateName}
102
+ tengo stacktrace:
103
+ ${tengoStacktrace}
104
+ `;
105
+ super(msg);
106
+ this.rawBackendMessage = rawBackendMessage;
107
+ this.templateName = templateName;
108
+ this.tengoMessage = tengoMessage;
109
+ this.tengoStacktrace = tengoStacktrace;
110
+ this.name = 'PlTengoError';
111
+ this.fullMessage = `${msg}
112
+ raw message:
113
+ ${this.rawBackendMessage}
114
+ `;
115
+ }
116
+ }
117
+ /**
118
+ * Happens when a command fails to run.
119
+ */
120
+ class PlRunnerError extends Error {
121
+ rawBackendMessage;
122
+ commandName;
123
+ exitCode;
124
+ stdout;
125
+ workingDirectory;
126
+ fullMessage;
127
+ constructor(rawBackendMessage, commandName, exitCode, stdout, workingDirectory) {
128
+ const msg = `PlRunnerError:
129
+ command: ${commandName}
130
+ exit code: ${exitCode}
131
+ working directory: ${workingDirectory}
132
+ stdout:
133
+ ${stdout}`;
134
+ super(msg);
135
+ this.rawBackendMessage = rawBackendMessage;
136
+ this.commandName = commandName;
137
+ this.exitCode = exitCode;
138
+ this.stdout = stdout;
139
+ this.workingDirectory = workingDirectory;
140
+ this.name = 'PlRunnerError';
141
+ this.fullMessage = `
142
+ ${msg}
143
+ raw message:
144
+ ${this.rawBackendMessage}
145
+ `;
146
+ }
147
+ }
148
+ /**
149
+ * Happens when a monetization command fails to run.
150
+ */
151
+ class PlMonetizationError extends PlRunnerError {
152
+ fullMessage;
153
+ constructor(rawBackendMessage, commandName, exitCode, stdout, workingDirectory) {
154
+ super(rawBackendMessage, commandName, exitCode, stdout, workingDirectory);
155
+ const msg = `Monetizaiton error:
156
+ ${this.stdout}
157
+ `;
158
+ this.message = msg;
159
+ this.name = 'PlMonetizationError';
160
+ this.fullMessage = `
161
+ ${msg}
162
+ command: ${this.commandName}
163
+ exit code: ${this.exitCode}
164
+ working directory: ${this.workingDirectory}
165
+
166
+ raw message:
167
+ ${this.rawBackendMessage}
168
+ `;
169
+ }
170
+ }
171
+ /**
172
+ * How the Pl backend represents an error.
173
+ */
174
+ const backendErrorSchema = zod.z.object({
175
+ errorType: zod.z.string().default(''),
176
+ message: zod.z.string(),
177
+ });
178
+ /**
179
+ * Parses a Pl error and suberrors from the Pl backend.
180
+ */
181
+ function parsePlError(error, resource, resourceType, field) {
182
+ const parsed = backendErrorSchema.safeParse(JSON.parse(error));
183
+ if (!parsed.success) {
184
+ throw new Error(`parsePlError: failed to parse the message, got ${error}`);
185
+ }
186
+ const errors = parseSubErrors(parsed.data.message);
187
+ return new PlErrorReport(error, parsed.data.errorType, parsed.data.message, errors, field, resource, resourceType);
188
+ }
189
+ /**
190
+ * Reduces over the lines of the pl error message
191
+ * to extract messages, and categorizes them.
192
+ */
193
+ function parseSubErrors(message) {
194
+ // the state of this reducing function
195
+ const state = {
196
+ stage: 'initial',
197
+ value: [],
198
+ result: [],
199
+ };
200
+ for (const line of message.split('\n')) {
201
+ if (state.stage == 'initial') {
202
+ // we need initial stage because apparently the first line
203
+ // of the error doesn't have [I], but is a path line.
204
+ state.stage = 'path';
205
+ }
206
+ else if (state.stage == 'path' && line.startsWith('---')) ;
207
+ else if (state.stage == 'path' && !isPath(line)) {
208
+ state.stage = 'message';
209
+ }
210
+ else if (state.stage == 'message' && isPath(line)) {
211
+ state.stage = 'path';
212
+ const text = state.value.join('\n');
213
+ state.result.push(parseCoreError(text));
214
+ state.value = [];
215
+ }
216
+ state.value.push(line);
217
+ }
218
+ const text = state.value.join('\n');
219
+ state.result.push(parseCoreError(text));
220
+ return state.result;
221
+ }
222
+ function isPath(line) {
223
+ for (const fieldType of ['U', 'I', 'O', 'S', 'OTW', 'D', 'MTW']) {
224
+ if (line.startsWith(`[${fieldType}]`))
225
+ return true;
226
+ }
227
+ return false;
228
+ }
229
+ /**
230
+ * Parses a suberror from the Pl backend.
231
+ */
232
+ function parseCoreError(message) {
233
+ // trying to parse a runner or monetization error.
234
+ // https://regex101.com/r/tmKLj7/1
235
+ const runnerErrorRegex = /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]*)/;
236
+ const match = message.match(runnerErrorRegex);
237
+ if (match) {
238
+ const workingDirectory = match[1];
239
+ const command = match[2];
240
+ const exitCode = parseInt(match[3], 10);
241
+ const stdout = match[4].trim();
242
+ if (command.endsWith(`mnz-client`) && exitCode == 1) {
243
+ return new PlMonetizationError(message, command, exitCode, stdout, workingDirectory);
244
+ }
245
+ return new PlRunnerError(message, command, exitCode, stdout, workingDirectory);
246
+ }
247
+ // trying to parse a Tengo error.
248
+ // https://regex101.com/r/1a7RpO/1
249
+ const workflowErrorRegex = /cannot eval code: cannot eval template: template: (.+)\n\t(.*?)\n\t(at [\s\S]*)/;
250
+ const workflowMatch = message.match(workflowErrorRegex);
251
+ if (workflowMatch) {
252
+ const templateName = workflowMatch[1];
253
+ const errorMessage = workflowMatch[2];
254
+ const stackTrace = workflowMatch[3];
255
+ return new PlTengoError(message, templateName, errorMessage, stackTrace);
256
+ }
257
+ // if we couldn't parse the error, return a general error.
258
+ return new PlInternalError(message);
259
+ }
260
+
261
+ exports.PlErrorReport = PlErrorReport;
262
+ exports.PlInternalError = PlInternalError;
263
+ exports.PlMonetizationError = PlMonetizationError;
264
+ exports.PlQuickJSError = PlQuickJSError;
265
+ exports.PlRunnerError = PlRunnerError;
266
+ exports.PlTengoError = PlTengoError;
267
+ exports.parsePlError = parsePlError;
268
+ exports.parseSubErrors = parseSubErrors;
269
+ //# sourceMappingURL=parsed_error.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsed_error.cjs","sources":["../src/parsed_error.ts"],"sourcesContent":["/** 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(\n quickJSError: Error,\n cause: Error,\n ) {\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 = '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 =\n | PlInternalError\n | PlTengoError\n | PlRunnerError\n | 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(\n public readonly message: string,\n ) {\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.object({\n errorType: z.string().default(''),\n message: z.string(),\n});\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}]`))\n 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 = /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 = /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"],"names":["notEmpty","resourceTypeToString","resourceIdToString","z"],"mappings":";;;;;;AAAA;AAOA;AACM,MAAO,cAAe,SAAQ,KAAK,CAAA;AAChC,IAAA,KAAK;AACL,IAAA,WAAW;IAElB,WAAA,CACE,YAAmB,EACnB,KAAY,EAAA;QAEZ,KAAK,CAAC,CAAA,gBAAA,EAAmB,KAAK,CAAC,OAAO,CAAA,CAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AACpD,QAAA,IA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AC,kBAAkB,CAAC;IACvD,IAAI,aAAa,EAAE;AACjB,QAAA,MAAM,YAAY,GAAG,aAAa,CAAC,CAAC,CAAC;AACrC,QAAA,MAAM,YAAY,GAAG,aAAa,CAAC,CAAC,CAAC;AACrC,QAAA,MAAM,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;QAEnC,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,CAAC;IAC1E;;AAGA,IAAA,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC;AACrC;;;;;;;;;;;"}
@@ -86,4 +86,3 @@ export declare function parsePlError(error: string, resource?: ResourceId, resou
86
86
  * to extract messages, and categorizes them.
87
87
  */
88
88
  export declare function parseSubErrors(message: string): PlCoreError[];
89
- //# sourceMappingURL=parsed_error.d.ts.map
@@ -0,0 +1,260 @@
1
+ import { z } from 'zod';
2
+ import { resourceTypeToString, resourceIdToString } from '@milaboratories/pl-client';
3
+ import { notEmpty } from '@milaboratories/ts-helpers';
4
+
5
+ /** Pl Backend throws arbitrary errors, and we're trying to parse them here. */
6
+ /** The error that comes from QuickJS. */
7
+ class PlQuickJSError extends Error {
8
+ stack;
9
+ fullMessage;
10
+ constructor(quickJSError, cause) {
11
+ super(`PlQuickJSError: ${cause.message}`, { cause });
12
+ this.name = 'PlQuickJSError';
13
+ // QuickJS wraps the error with the name and the message,
14
+ // but we need another format.
15
+ let stack = notEmpty(quickJSError.stack);
16
+ stack = stack.replace(quickJSError.message, '');
17
+ stack = stack.replace(notEmpty(cause.message), '');
18
+ this.stack = stack;
19
+ const causeMsg = 'fullMessage' in cause && typeof cause.fullMessage === 'string'
20
+ ? cause.fullMessage
21
+ : cause.message;
22
+ this.fullMessage = `PlQuickJSError: ${causeMsg}
23
+ QuickJS stacktrace:
24
+ ${this.stack}
25
+ `;
26
+ }
27
+ }
28
+ /**
29
+ * A parsed error from the Pl backend.
30
+ * It contains several suberrors, which could be one or different causes of the error.
31
+ */
32
+ class PlErrorReport extends Error {
33
+ rawBackendMessage;
34
+ plErrorType;
35
+ plMessage;
36
+ errors;
37
+ fieldName;
38
+ resource;
39
+ resourceType;
40
+ fullMessage;
41
+ constructor(
42
+ /** Full message from the Pl backend. */
43
+ rawBackendMessage,
44
+ /** Either CID conflict or a error from controller. */
45
+ plErrorType,
46
+ /** Parsed pl backend message that will be futher parsed into suberrors. */
47
+ plMessage,
48
+ /** Could be several different errors, the name is from AggregateError. */
49
+ errors,
50
+ /** Optional info about a resource where the error happened. */
51
+ fieldName, resource, resourceType) {
52
+ const errorMessages = errors.map((e) => e.message).join('\n\n');
53
+ const errorFullMessages = errors.map((e) => e.fullMessage).join('\n\n');
54
+ super(`PlErrorReport: ${errorMessages}`);
55
+ this.rawBackendMessage = rawBackendMessage;
56
+ this.plErrorType = plErrorType;
57
+ this.plMessage = plMessage;
58
+ this.errors = errors;
59
+ this.fieldName = fieldName;
60
+ this.resource = resource;
61
+ this.resourceType = resourceType;
62
+ this.name = 'PlErrorReport';
63
+ const rt = this.resourceType ? `${resourceTypeToString(this.resourceType)},` : '';
64
+ const r = this.resource ? resourceIdToString(this.resource) : '';
65
+ const f = this.fieldName ? `/${this.fieldName}` : '';
66
+ const errType = this.plErrorType ? `error type: ${this.plErrorType}` : '';
67
+ this.fullMessage = `PlErrorReport: resource: ${rt} ${r}${f}
68
+ ${errType}
69
+ ${errorFullMessages}
70
+ `;
71
+ }
72
+ }
73
+ /**
74
+ * An general error when we couldn't parse the cause.
75
+ */
76
+ class PlInternalError extends Error {
77
+ message;
78
+ fullMessage;
79
+ constructor(message) {
80
+ super(message);
81
+ this.message = message;
82
+ this.name = 'PlInternalError';
83
+ this.fullMessage = `PlInternalError: ${message}`;
84
+ }
85
+ }
86
+ /**
87
+ * Happens when workflow template panics.
88
+ */
89
+ class PlTengoError extends Error {
90
+ rawBackendMessage;
91
+ templateName;
92
+ tengoMessage;
93
+ tengoStacktrace;
94
+ fullMessage;
95
+ constructor(rawBackendMessage, templateName, tengoMessage, tengoStacktrace) {
96
+ const msg = `PlTengoError:
97
+ message:
98
+ ${tengoMessage}
99
+ template: ${templateName}
100
+ tengo stacktrace:
101
+ ${tengoStacktrace}
102
+ `;
103
+ super(msg);
104
+ this.rawBackendMessage = rawBackendMessage;
105
+ this.templateName = templateName;
106
+ this.tengoMessage = tengoMessage;
107
+ this.tengoStacktrace = tengoStacktrace;
108
+ this.name = 'PlTengoError';
109
+ this.fullMessage = `${msg}
110
+ raw message:
111
+ ${this.rawBackendMessage}
112
+ `;
113
+ }
114
+ }
115
+ /**
116
+ * Happens when a command fails to run.
117
+ */
118
+ class PlRunnerError extends Error {
119
+ rawBackendMessage;
120
+ commandName;
121
+ exitCode;
122
+ stdout;
123
+ workingDirectory;
124
+ fullMessage;
125
+ constructor(rawBackendMessage, commandName, exitCode, stdout, workingDirectory) {
126
+ const msg = `PlRunnerError:
127
+ command: ${commandName}
128
+ exit code: ${exitCode}
129
+ working directory: ${workingDirectory}
130
+ stdout:
131
+ ${stdout}`;
132
+ super(msg);
133
+ this.rawBackendMessage = rawBackendMessage;
134
+ this.commandName = commandName;
135
+ this.exitCode = exitCode;
136
+ this.stdout = stdout;
137
+ this.workingDirectory = workingDirectory;
138
+ this.name = 'PlRunnerError';
139
+ this.fullMessage = `
140
+ ${msg}
141
+ raw message:
142
+ ${this.rawBackendMessage}
143
+ `;
144
+ }
145
+ }
146
+ /**
147
+ * Happens when a monetization command fails to run.
148
+ */
149
+ class PlMonetizationError extends PlRunnerError {
150
+ fullMessage;
151
+ constructor(rawBackendMessage, commandName, exitCode, stdout, workingDirectory) {
152
+ super(rawBackendMessage, commandName, exitCode, stdout, workingDirectory);
153
+ const msg = `Monetizaiton error:
154
+ ${this.stdout}
155
+ `;
156
+ this.message = msg;
157
+ this.name = 'PlMonetizationError';
158
+ this.fullMessage = `
159
+ ${msg}
160
+ command: ${this.commandName}
161
+ exit code: ${this.exitCode}
162
+ working directory: ${this.workingDirectory}
163
+
164
+ raw message:
165
+ ${this.rawBackendMessage}
166
+ `;
167
+ }
168
+ }
169
+ /**
170
+ * How the Pl backend represents an error.
171
+ */
172
+ const backendErrorSchema = z.object({
173
+ errorType: z.string().default(''),
174
+ message: z.string(),
175
+ });
176
+ /**
177
+ * Parses a Pl error and suberrors from the Pl backend.
178
+ */
179
+ function parsePlError(error, resource, resourceType, field) {
180
+ const parsed = backendErrorSchema.safeParse(JSON.parse(error));
181
+ if (!parsed.success) {
182
+ throw new Error(`parsePlError: failed to parse the message, got ${error}`);
183
+ }
184
+ const errors = parseSubErrors(parsed.data.message);
185
+ return new PlErrorReport(error, parsed.data.errorType, parsed.data.message, errors, field, resource, resourceType);
186
+ }
187
+ /**
188
+ * Reduces over the lines of the pl error message
189
+ * to extract messages, and categorizes them.
190
+ */
191
+ function parseSubErrors(message) {
192
+ // the state of this reducing function
193
+ const state = {
194
+ stage: 'initial',
195
+ value: [],
196
+ result: [],
197
+ };
198
+ for (const line of message.split('\n')) {
199
+ if (state.stage == 'initial') {
200
+ // we need initial stage because apparently the first line
201
+ // of the error doesn't have [I], but is a path line.
202
+ state.stage = 'path';
203
+ }
204
+ else if (state.stage == 'path' && line.startsWith('---')) ;
205
+ else if (state.stage == 'path' && !isPath(line)) {
206
+ state.stage = 'message';
207
+ }
208
+ else if (state.stage == 'message' && isPath(line)) {
209
+ state.stage = 'path';
210
+ const text = state.value.join('\n');
211
+ state.result.push(parseCoreError(text));
212
+ state.value = [];
213
+ }
214
+ state.value.push(line);
215
+ }
216
+ const text = state.value.join('\n');
217
+ state.result.push(parseCoreError(text));
218
+ return state.result;
219
+ }
220
+ function isPath(line) {
221
+ for (const fieldType of ['U', 'I', 'O', 'S', 'OTW', 'D', 'MTW']) {
222
+ if (line.startsWith(`[${fieldType}]`))
223
+ return true;
224
+ }
225
+ return false;
226
+ }
227
+ /**
228
+ * Parses a suberror from the Pl backend.
229
+ */
230
+ function parseCoreError(message) {
231
+ // trying to parse a runner or monetization error.
232
+ // https://regex101.com/r/tmKLj7/1
233
+ const runnerErrorRegex = /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]*)/;
234
+ const match = message.match(runnerErrorRegex);
235
+ if (match) {
236
+ const workingDirectory = match[1];
237
+ const command = match[2];
238
+ const exitCode = parseInt(match[3], 10);
239
+ const stdout = match[4].trim();
240
+ if (command.endsWith(`mnz-client`) && exitCode == 1) {
241
+ return new PlMonetizationError(message, command, exitCode, stdout, workingDirectory);
242
+ }
243
+ return new PlRunnerError(message, command, exitCode, stdout, workingDirectory);
244
+ }
245
+ // trying to parse a Tengo error.
246
+ // https://regex101.com/r/1a7RpO/1
247
+ const workflowErrorRegex = /cannot eval code: cannot eval template: template: (.+)\n\t(.*?)\n\t(at [\s\S]*)/;
248
+ const workflowMatch = message.match(workflowErrorRegex);
249
+ if (workflowMatch) {
250
+ const templateName = workflowMatch[1];
251
+ const errorMessage = workflowMatch[2];
252
+ const stackTrace = workflowMatch[3];
253
+ return new PlTengoError(message, templateName, errorMessage, stackTrace);
254
+ }
255
+ // if we couldn't parse the error, return a general error.
256
+ return new PlInternalError(message);
257
+ }
258
+
259
+ export { PlErrorReport, PlInternalError, PlMonetizationError, PlQuickJSError, PlRunnerError, PlTengoError, parsePlError, parseSubErrors };
260
+ //# sourceMappingURL=parsed_error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsed_error.js","sources":["../src/parsed_error.ts"],"sourcesContent":["/** 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(\n quickJSError: Error,\n cause: Error,\n ) {\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 = '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 =\n | PlInternalError\n | PlTengoError\n | PlRunnerError\n | 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(\n public readonly message: string,\n ) {\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.object({\n errorType: z.string().default(''),\n message: z.string(),\n});\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}]`))\n 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 = /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 = /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"],"names":[],"mappings":";;;;AAAA;AAOA;AACM,MAAO,cAAe,SAAQ,KAAK,CAAA;AAChC,IAAA,KAAK;AACL,IAAA,WAAW;IAElB,WAAA,CACE,YAAmB,EACnB,KAAY,EAAA;QAEZ,KAAK,CAAC,CAAA,gBAAA,EAAmB,KAAK,CAAC,OAAO,CAAA,CAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AACpD,QAAA,IAAI,CAAC,IAAI,GAAG,gBAAgB;;;QAI5B,IAAI,KAAK,GAAG,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC;QACxC,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC;AAC/C,QAAA,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;AAElD,QAAA,IAAI,CAAC,KAAK,GAAG,KAAK;QAElB,MAAM,QAAQ,GAAG,aAAa,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,WAAW,KAAK;cACpE,KAAK,CAAC;AACR,cAAE,KAAK,CAAC,OAAO;AAEjB,QAAA,IAAI,CAAC,WAAW,GAAG,CAAA,gBAAA,EAAmB,QAAQ;;AAEhD,EAAA,IAAI,CAAC,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AAgB,CAAC;IAC7C,IAAI,KAAK,EAAE;AACT,QAAA,MAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,CAAC;AACjC,QAAA,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC;QACxB,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;QAE9B,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAA,UAAA,CAAY,CAAC,IAAI,QAAQ,IAAI,CAAC,EAAE;AACnD,YAAA,OAAO,IAAI,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,CAAC;QACtF;AAEA,QAAA,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,CAAC;IAChF;;;IAIA,MAAM,kBAAkB,GAAG,iFAAiF;IAC5G,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC;IACvD,IAAI,aAAa,EAAE;AACjB,QAAA,MAAM,YAAY,GAAG,aAAa,CAAC,CAAC,CAAC;AACrC,QAAA,MAAM,YAAY,GAAG,aAAa,CAAC,CAAC,CAAC;AACrC,QAAA,MAAM,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;QAEnC,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,CAAC;IAC1E;;AAGA,IAAA,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC;AACrC;;;;"}
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@milaboratories/pl-errors",
3
- "version": "1.1.14",
3
+ "version": "1.1.16",
4
4
  "description": "Parsing errors from Pl backend",
5
5
  "types": "./dist/index.d.ts",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.mjs",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
- "require": "./dist/index.js",
12
- "import": "./dist/index.mjs"
11
+ "require": "./dist/index.cjs",
12
+ "import": "./dist/index.js"
13
13
  }
14
14
  },
15
15
  "files": [
@@ -18,22 +18,24 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "zod": "~3.23.8",
21
- "@milaboratories/pl-client": "2.11.7",
22
- "@milaboratories/ts-helpers": "1.4.3"
21
+ "@milaboratories/pl-client": "2.11.9",
22
+ "@milaboratories/ts-helpers": "1.4.4"
23
23
  },
24
24
  "devDependencies": {
25
25
  "typescript": "~5.6.3",
26
- "vite": "^6.3.5",
27
26
  "vitest": "^2.1.9",
28
- "@milaboratories/pl-error-like": "1.12.2",
27
+ "@milaboratories/pl-error-like": "1.12.3",
28
+ "@milaboratories/ts-builder": "1.0.1",
29
29
  "@milaboratories/eslint-config": "^1.0.4",
30
- "@milaboratories/build-configs": "1.0.5"
30
+ "@milaboratories/build-configs": "1.0.6",
31
+ "@milaboratories/ts-configs": "1.0.6"
31
32
  },
32
33
  "scripts": {
33
- "type-check": "tsc --noEmit --composite false",
34
- "build": "vite build",
34
+ "type-check": "ts-builder types --target node",
35
+ "build": "ts-builder build --target node",
36
+ "build:watch": "ts-builder build --target node --watch",
35
37
  "lint": "eslint .",
36
- "test": "vitest",
38
+ "test": "vitest run",
37
39
  "do-pack": "rm -f *.tgz && pnpm pack && mv *.tgz package.tgz"
38
40
  }
39
41
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
package/dist/index.mjs DELETED
@@ -1,172 +0,0 @@
1
- var P = Object.defineProperty;
2
- var y = (t, e, r) => e in t ? P(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var c = (t, e, r) => y(t, typeof e != "symbol" ? e + "" : e, r);
4
- import { z as h } from "zod";
5
- import { resourceTypeToString as T, resourceIdToString as x } from "@milaboratories/pl-client";
6
- import { notEmpty as g } from "@milaboratories/ts-helpers";
7
- class W extends Error {
8
- constructor(r, o) {
9
- super(`PlQuickJSError: ${o.message}`, { cause: o });
10
- c(this, "stack");
11
- c(this, "fullMessage");
12
- this.name = "PlQuickJSError";
13
- let s = g(r.stack);
14
- s = s.replace(r.message, ""), s = s.replace(g(o.message), ""), this.stack = s;
15
- const a = "fullMessage" in o && typeof o.fullMessage == "string" ? o.fullMessage : o.message;
16
- this.fullMessage = `PlQuickJSError: ${a}
17
- QuickJS stacktrace:
18
- ${this.stack}
19
- `;
20
- }
21
- }
22
- class S extends Error {
23
- constructor(r, o, s, a, n, i, l) {
24
- const d = a.map((u) => u.message).join(`
25
-
26
- `), E = a.map((u) => u.fullMessage).join(`
27
-
28
- `);
29
- super(`PlErrorReport: ${d}`);
30
- c(this, "fullMessage");
31
- this.rawBackendMessage = r, this.plErrorType = o, this.plMessage = s, this.errors = a, this.fieldName = n, this.resource = i, this.resourceType = l, this.name = "PlErrorReport";
32
- const M = this.resourceType ? `${T(this.resourceType)},` : "", $ = this.resource ? x(this.resource) : "", k = this.fieldName ? `/${this.fieldName}` : "", w = this.plErrorType ? `error type: ${this.plErrorType}` : "";
33
- this.fullMessage = `PlErrorReport: resource: ${M} ${$}${k}
34
- ${w}
35
- ${E}
36
- `;
37
- }
38
- }
39
- class R extends Error {
40
- constructor(r) {
41
- super(r);
42
- c(this, "fullMessage");
43
- this.message = r, this.name = "PlInternalError", this.fullMessage = `PlInternalError: ${r}`;
44
- }
45
- }
46
- class v extends Error {
47
- constructor(r, o, s, a) {
48
- const n = `PlTengoError:
49
- message:
50
- ${s}
51
- template: ${o}
52
- tengo stacktrace:
53
- ${a}
54
- `;
55
- super(n);
56
- c(this, "fullMessage");
57
- this.rawBackendMessage = r, this.templateName = o, this.tengoMessage = s, this.tengoStacktrace = a, this.name = "PlTengoError", this.fullMessage = `${n}
58
- raw message:
59
- ${this.rawBackendMessage}
60
- `;
61
- }
62
- }
63
- class f extends Error {
64
- constructor(r, o, s, a, n) {
65
- const i = `PlRunnerError:
66
- command: ${o}
67
- exit code: ${s}
68
- working directory: ${n}
69
- stdout:
70
- ${a}`;
71
- super(i);
72
- c(this, "fullMessage");
73
- this.rawBackendMessage = r, this.commandName = o, this.exitCode = s, this.stdout = a, this.workingDirectory = n, this.name = "PlRunnerError", this.fullMessage = `
74
- ${i}
75
- raw message:
76
- ${this.rawBackendMessage}
77
- `;
78
- }
79
- }
80
- class B extends f {
81
- constructor(r, o, s, a, n) {
82
- super(r, o, s, a, n);
83
- c(this, "fullMessage");
84
- const i = `Monetizaiton error:
85
- ${this.stdout}
86
- `;
87
- this.message = i, this.name = "PlMonetizationError", this.fullMessage = `
88
- ${i}
89
- command: ${this.commandName}
90
- exit code: ${this.exitCode}
91
- working directory: ${this.workingDirectory}
92
-
93
- raw message:
94
- ${this.rawBackendMessage}
95
- `;
96
- }
97
- }
98
- const I = h.object({
99
- errorType: h.string().default(""),
100
- message: h.string()
101
- });
102
- function b(t, e, r, o) {
103
- const s = I.safeParse(JSON.parse(t));
104
- if (!s.success)
105
- throw new Error(`parsePlError: failed to parse the message, got ${t}`);
106
- const a = N(s.data.message);
107
- return new S(
108
- t,
109
- s.data.errorType,
110
- s.data.message,
111
- a,
112
- o,
113
- e,
114
- r
115
- );
116
- }
117
- function N(t) {
118
- const e = {
119
- stage: "initial",
120
- value: [],
121
- result: []
122
- };
123
- for (const o of t.split(`
124
- `)) {
125
- if (e.stage == "initial")
126
- e.stage = "path";
127
- else if (!(e.stage == "path" && o.startsWith("---"))) {
128
- if (e.stage == "path" && !p(o))
129
- e.stage = "message";
130
- else if (e.stage == "message" && p(o)) {
131
- e.stage = "path";
132
- const s = e.value.join(`
133
- `);
134
- e.result.push(m(s)), e.value = [];
135
- }
136
- }
137
- e.value.push(o);
138
- }
139
- const r = e.value.join(`
140
- `);
141
- return e.result.push(m(r)), e.result;
142
- }
143
- function p(t) {
144
- for (const e of ["U", "I", "O", "S", "OTW", "D", "MTW"])
145
- if (t.startsWith(`[${e}]`))
146
- return !0;
147
- return !1;
148
- }
149
- function m(t) {
150
- const e = /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]*)/, r = t.match(e);
151
- if (r) {
152
- const a = r[1], n = r[2], i = parseInt(r[3], 10), l = r[4].trim();
153
- return n.endsWith("mnz-client") && i == 1 ? new B(t, n, i, l, a) : new f(t, n, i, l, a);
154
- }
155
- const o = /cannot eval code: cannot eval template: template: (.+)\n\t(.*?)\n\t(at [\s\S]*)/, s = t.match(o);
156
- if (s) {
157
- const a = s[1], n = s[2], i = s[3];
158
- return new v(t, a, n, i);
159
- }
160
- return new R(t);
161
- }
162
- export {
163
- S as PlErrorReport,
164
- R as PlInternalError,
165
- B as PlMonetizationError,
166
- W as PlQuickJSError,
167
- f as PlRunnerError,
168
- v as PlTengoError,
169
- b as parsePlError,
170
- N as parseSubErrors
171
- };
172
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/parsed_error.ts"],"sourcesContent":["/** 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(\n quickJSError: Error,\n cause: Error,\n ) {\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 = '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 =\n | PlInternalError\n | PlTengoError\n | PlRunnerError\n | 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(\n public readonly message: string,\n ) {\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.object({\n errorType: z.string().default(''),\n message: z.string(),\n});\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}]`))\n 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 = /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 = /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"],"names":["PlQuickJSError","quickJSError","cause","__publicField","stack","notEmpty","causeMsg","PlErrorReport","rawBackendMessage","plErrorType","plMessage","errors","fieldName","resource","resourceType","errorMessages","e","errorFullMessages","rt","resourceTypeToString","r","resourceIdToString","f","errType","PlInternalError","message","PlTengoError","templateName","tengoMessage","tengoStacktrace","msg","PlRunnerError","commandName","exitCode","stdout","workingDirectory","PlMonetizationError","backendErrorSchema","z","parsePlError","error","field","parsed","parseSubErrors","state","line","isPath","text","parseCoreError","fieldType","runnerErrorRegex","match","command","workflowErrorRegex","workflowMatch","errorMessage","stackTrace"],"mappings":";;;;;;AAQO,MAAMA,UAAuB,MAAM;AAAA,EAIxC,YACEC,GACAC,GACA;AACA,UAAM,mBAAmBA,EAAM,OAAO,IAAI,EAAE,OAAAA,GAAO;AAP9C,IAAAC,EAAA;AACA,IAAAA,EAAA;AAOL,SAAK,OAAO;AAIR,QAAAC,IAAQC,EAASJ,EAAa,KAAK;AACvC,IAAAG,IAAQA,EAAM,QAAQH,EAAa,SAAS,EAAE,GAC9CG,IAAQA,EAAM,QAAQC,EAASH,EAAM,OAAO,GAAG,EAAE,GAEjD,KAAK,QAAQE;AAEP,UAAAE,IAAW,iBAAiBJ,KAAS,OAAOA,EAAM,eAAgB,WACpEA,EAAM,cACNA,EAAM;AAEL,SAAA,cAAc,mBAAmBI,CAAQ;AAAA;AAAA,EAEhD,KAAK,KAAK;AAAA;AAAA,EAAA;AAGZ;AAMO,MAAMC,UAAsB,M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