@milaboratories/pl-errors 1.1.69 → 1.1.71

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 CHANGED
@@ -1,15 +1,11 @@
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
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_parsed_error = require('./parsed_error.cjs');
3
+
4
+ exports.PlErrorReport = require_parsed_error.PlErrorReport;
5
+ exports.PlInternalError = require_parsed_error.PlInternalError;
6
+ exports.PlMonetizationError = require_parsed_error.PlMonetizationError;
7
+ exports.PlQuickJSError = require_parsed_error.PlQuickJSError;
8
+ exports.PlRunnerError = require_parsed_error.PlRunnerError;
9
+ exports.PlTengoError = require_parsed_error.PlTengoError;
10
+ exports.parsePlError = require_parsed_error.parsePlError;
11
+ exports.parseSubErrors = require_parsed_error.parseSubErrors;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./parsed_error";
2
- //# sourceMappingURL=index.d.ts.map
1
+ import { PlCoreError, PlErrorReport, PlInternalError, PlMonetizationError, PlQuickJSError, PlRunnerError, PlTengoError, parsePlError, parseSubErrors } from "./parsed_error.js";
2
+ export { PlCoreError, PlErrorReport, PlInternalError, PlMonetizationError, PlQuickJSError, PlRunnerError, PlTengoError, parsePlError, parseSubErrors };
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
- export { PlErrorReport, PlInternalError, PlMonetizationError, PlQuickJSError, PlRunnerError, PlTengoError, parsePlError, parseSubErrors } from './parsed_error.js';
2
- //# sourceMappingURL=index.js.map
1
+ import { PlErrorReport, PlInternalError, PlMonetizationError, PlQuickJSError, PlRunnerError, PlTengoError, parsePlError, parseSubErrors } from "./parsed_error.js";
2
+
3
+ export { PlErrorReport, PlInternalError, PlMonetizationError, PlQuickJSError, PlRunnerError, PlTengoError, parsePlError, parseSubErrors };
@@ -1,163 +1,126 @@
1
- 'use strict';
2
-
3
- var zod = require('zod');
4
- var plClient = require('@milaboratories/pl-client');
5
- var tsHelpers = require('@milaboratories/ts-helpers');
1
+ let zod = require("zod");
2
+ let _milaboratories_pl_client = require("@milaboratories/pl-client");
3
+ let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
6
4
 
5
+ //#region src/parsed_error.ts
7
6
  /** Pl Backend throws arbitrary errors, and we're trying to parse them here. */
8
7
  /** 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}
8
+ var PlQuickJSError = class extends Error {
9
+ stack;
10
+ fullMessage;
11
+ constructor(quickJSError, cause) {
12
+ super(`PlQuickJSError: ${cause.message}`, { cause });
13
+ this.name = "PlQuickJSError";
14
+ let stack = (0, _milaboratories_ts_helpers.notEmpty)(quickJSError.stack);
15
+ stack = stack.replace(quickJSError.message, "");
16
+ stack = stack.replace((0, _milaboratories_ts_helpers.notEmpty)(cause.message), "");
17
+ this.stack = stack;
18
+ this.fullMessage = `PlQuickJSError: ${"fullMessage" in cause && typeof cause.fullMessage === "string" ? cause.fullMessage : cause.message}
25
19
  QuickJS stacktrace:
26
20
  ${this.stack}
27
21
  `;
28
- }
29
- }
22
+ }
23
+ };
30
24
  /**
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}
25
+ * A parsed error from the Pl backend.
26
+ * It contains several suberrors, which could be one or different causes of the error.
27
+ */
28
+ var PlErrorReport = class extends Error {
29
+ fullMessage;
30
+ constructor(rawBackendMessage, plErrorType, plMessage, errors, fieldName, resource, resourceType) {
31
+ const errorMessages = errors.map((e) => e.message).join("\n\n");
32
+ const errorFullMessages = errors.map((e) => e.fullMessage).join("\n\n");
33
+ super(`PlErrorReport: ${errorMessages}`);
34
+ this.rawBackendMessage = rawBackendMessage;
35
+ this.plErrorType = plErrorType;
36
+ this.plMessage = plMessage;
37
+ this.errors = errors;
38
+ this.fieldName = fieldName;
39
+ this.resource = resource;
40
+ this.resourceType = resourceType;
41
+ this.name = "PlErrorReport";
42
+ this.fullMessage = `PlErrorReport: resource: ${this.resourceType ? `${(0, _milaboratories_pl_client.resourceTypeToString)(this.resourceType)},` : ""} ${this.resource ? (0, _milaboratories_pl_client.resourceIdToString)(this.resource) : ""}${this.fieldName ? `/${this.fieldName}` : ""}
43
+ ${this.plErrorType ? `error type: ${this.plErrorType}` : ""}
71
44
  ${errorFullMessages}
72
45
  `;
73
- }
74
- }
46
+ }
47
+ };
75
48
  /**
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
- }
49
+ * An general error when we couldn't parse the cause.
50
+ */
51
+ var PlInternalError = class extends Error {
52
+ fullMessage;
53
+ constructor(message) {
54
+ super(message);
55
+ this.message = message;
56
+ this.name = "PlInternalError";
57
+ this.fullMessage = `PlInternalError: ${message}`;
58
+ }
59
+ };
88
60
  /**
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:
61
+ * Happens when workflow template panics.
62
+ */
63
+ var PlTengoError = class extends Error {
64
+ fullMessage;
65
+ constructor(rawBackendMessage, templateName, tengoMessage, tengoStacktrace) {
66
+ const msg = `PlTengoError:
99
67
  message:
100
68
  ${tengoMessage}
101
69
  template: ${templateName}
102
70
  tengo stacktrace:
103
71
  ${tengoStacktrace}
104
72
  `;
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}
73
+ super(msg);
74
+ this.rawBackendMessage = rawBackendMessage;
75
+ this.templateName = templateName;
76
+ this.tengoMessage = tengoMessage;
77
+ this.tengoStacktrace = tengoStacktrace;
78
+ this.name = "PlTengoError";
79
+ this.fullMessage = `${msg}
112
80
  raw message:
113
81
  ${this.rawBackendMessage}
114
82
  `;
115
- }
116
- }
83
+ }
84
+ };
117
85
  /**
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:
86
+ * Happens when a command fails to run.
87
+ */
88
+ var PlRunnerError = class extends Error {
89
+ fullMessage;
90
+ constructor(rawBackendMessage, commandName, exitCode, stdout, workingDirectory) {
91
+ const msg = `PlRunnerError:
129
92
  command: ${commandName}
130
93
  exit code: ${exitCode}
131
94
  working directory: ${workingDirectory}
132
95
  stdout:
133
96
  ${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 = `
97
+ super(msg);
98
+ this.rawBackendMessage = rawBackendMessage;
99
+ this.commandName = commandName;
100
+ this.exitCode = exitCode;
101
+ this.stdout = stdout;
102
+ this.workingDirectory = workingDirectory;
103
+ this.name = "PlRunnerError";
104
+ this.fullMessage = `
142
105
  ${msg}
143
106
  raw message:
144
107
  ${this.rawBackendMessage}
145
108
  `;
146
- }
147
- }
109
+ }
110
+ };
148
111
  /**
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:
112
+ * Happens when a monetization command fails to run.
113
+ */
114
+ var PlMonetizationError = class extends PlRunnerError {
115
+ fullMessage;
116
+ constructor(rawBackendMessage, commandName, exitCode, stdout, workingDirectory) {
117
+ super(rawBackendMessage, commandName, exitCode, stdout, workingDirectory);
118
+ const msg = `Monetizaiton error:
156
119
  ${this.stdout}
157
120
  `;
158
- this.message = msg;
159
- this.name = "PlMonetizationError";
160
- this.fullMessage = `
121
+ this.message = msg;
122
+ this.name = "PlMonetizationError";
123
+ this.fullMessage = `
161
124
  ${msg}
162
125
  command: ${this.commandName}
163
126
  exit code: ${this.exitCode}
@@ -166,100 +129,85 @@ working directory: ${this.workingDirectory}
166
129
  raw message:
167
130
  ${this.rawBackendMessage}
168
131
  `;
169
- }
170
- }
132
+ }
133
+ };
171
134
  /**
172
- * How the Pl backend represents an error.
173
- */
174
- const backendErrorSchema = zod.z
175
- .object({
176
- errorType: zod.z.string().default(""),
177
- message: zod.z.string(),
178
- })
179
- .passthrough();
135
+ * How the Pl backend represents an error.
136
+ */
137
+ const backendErrorSchema = zod.z.object({
138
+ errorType: zod.z.string().default(""),
139
+ message: zod.z.string()
140
+ }).passthrough();
180
141
  /**
181
- * Parses a Pl error and suberrors from the Pl backend.
182
- */
142
+ * Parses a Pl error and suberrors from the Pl backend.
143
+ */
183
144
  function parsePlError(error, resource, resourceType, field) {
184
- const parsed = backendErrorSchema.safeParse(JSON.parse(error));
185
- if (!parsed.success) {
186
- throw new Error(`parsePlError: failed to parse the message, got ${error}`);
187
- }
188
- const errors = parseSubErrors(parsed.data.message);
189
- return new PlErrorReport(error, parsed.data.errorType, parsed.data.message, errors, field, resource, resourceType);
145
+ const parsed = backendErrorSchema.safeParse(JSON.parse(error));
146
+ if (!parsed.success) throw new Error(`parsePlError: failed to parse the message, got ${error}`);
147
+ const errors = parseSubErrors(parsed.data.message);
148
+ return new PlErrorReport(error, parsed.data.errorType, parsed.data.message, errors, field, resource, resourceType);
190
149
  }
191
150
  /**
192
- * Reduces over the lines of the pl error message
193
- * to extract messages, and categorizes them.
194
- */
151
+ * Reduces over the lines of the pl error message
152
+ * to extract messages, and categorizes them.
153
+ */
195
154
  function parseSubErrors(message) {
196
- // the state of this reducing function
197
- const state = {
198
- stage: "initial",
199
- value: [],
200
- result: [],
201
- };
202
- for (const line of message.split("\n")) {
203
- if (state.stage == "initial") {
204
- // we need initial stage because apparently the first line
205
- // of the error doesn't have [I], but is a path line.
206
- state.stage = "path";
207
- }
208
- else if (state.stage == "path" && line.startsWith("---")) ;
209
- else if (state.stage == "path" && !isPath(line)) {
210
- state.stage = "message";
211
- }
212
- else if (state.stage == "message" && isPath(line)) {
213
- state.stage = "path";
214
- const text = state.value.join("\n");
215
- state.result.push(parseCoreError(text));
216
- state.value = [];
217
- }
218
- state.value.push(line);
219
- }
220
- const text = state.value.join("\n");
221
- state.result.push(parseCoreError(text));
222
- return state.result;
155
+ const state = {
156
+ stage: "initial",
157
+ value: [],
158
+ result: []
159
+ };
160
+ for (const line of message.split("\n")) {
161
+ if (state.stage == "initial") state.stage = "path";
162
+ else if (state.stage == "path" && line.startsWith("---")) {} else if (state.stage == "path" && !isPath(line)) state.stage = "message";
163
+ else if (state.stage == "message" && isPath(line)) {
164
+ state.stage = "path";
165
+ const text = state.value.join("\n");
166
+ state.result.push(parseCoreError(text));
167
+ state.value = [];
168
+ }
169
+ state.value.push(line);
170
+ }
171
+ const text = state.value.join("\n");
172
+ state.result.push(parseCoreError(text));
173
+ return state.result;
223
174
  }
224
175
  function isPath(line) {
225
- for (const fieldType of ["U", "I", "O", "S", "OTW", "D", "MTW"]) {
226
- if (line.startsWith(`[${fieldType}]`))
227
- return true;
228
- }
229
- return false;
176
+ for (const fieldType of [
177
+ "U",
178
+ "I",
179
+ "O",
180
+ "S",
181
+ "OTW",
182
+ "D",
183
+ "MTW"
184
+ ]) if (line.startsWith(`[${fieldType}]`)) return true;
185
+ return false;
230
186
  }
231
187
  /**
232
- * Parses a suberror from the Pl backend.
233
- */
188
+ * Parses a suberror from the Pl backend.
189
+ */
234
190
  function parseCoreError(message) {
235
- // trying to parse a runner or monetization error.
236
- // https://regex101.com/r/tmKLj7/1
237
- 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]*)/;
238
- const match = message.match(runnerErrorRegex);
239
- if (match) {
240
- const workingDirectory = match[1];
241
- const command = match[2];
242
- const exitCode = parseInt(match[3], 10);
243
- const stdout = match[4].trim();
244
- if (command.endsWith(`mnz-client`) && exitCode == 1) {
245
- return new PlMonetizationError(message, command, exitCode, stdout, workingDirectory);
246
- }
247
- return new PlRunnerError(message, command, exitCode, stdout, workingDirectory);
248
- }
249
- // trying to parse a Tengo error.
250
- // https://regex101.com/r/1a7RpO/1
251
- const workflowErrorRegex = /cannot eval code: cannot eval template: template: (.+)\n\t(.*?)\n\t(at [\s\S]*)/;
252
- const workflowMatch = message.match(workflowErrorRegex);
253
- if (workflowMatch) {
254
- const templateName = workflowMatch[1];
255
- const errorMessage = workflowMatch[2];
256
- const stackTrace = workflowMatch[3];
257
- return new PlTengoError(message, templateName, errorMessage, stackTrace);
258
- }
259
- // if we couldn't parse the error, return a general error.
260
- return new PlInternalError(message);
191
+ const match = message.match(/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]*)/);
192
+ if (match) {
193
+ const workingDirectory = match[1];
194
+ const command = match[2];
195
+ const exitCode = parseInt(match[3], 10);
196
+ const stdout = match[4].trim();
197
+ if (command.endsWith(`mnz-client`) && exitCode == 1) return new PlMonetizationError(message, command, exitCode, stdout, workingDirectory);
198
+ return new PlRunnerError(message, command, exitCode, stdout, workingDirectory);
199
+ }
200
+ const workflowMatch = message.match(/cannot eval code: cannot eval template: template: (.+)\n\t(.*?)\n\t(at [\s\S]*)/);
201
+ if (workflowMatch) {
202
+ const templateName = workflowMatch[1];
203
+ const errorMessage = workflowMatch[2];
204
+ const stackTrace = workflowMatch[3];
205
+ return new PlTengoError(message, templateName, errorMessage, stackTrace);
206
+ }
207
+ return new PlInternalError(message);
261
208
  }
262
209
 
210
+ //#endregion
263
211
  exports.PlErrorReport = PlErrorReport;
264
212
  exports.PlInternalError = PlInternalError;
265
213
  exports.PlMonetizationError = PlMonetizationError;
@@ -268,4 +216,4 @@ exports.PlRunnerError = PlRunnerError;
268
216
  exports.PlTengoError = PlTengoError;
269
217
  exports.parsePlError = parsePlError;
270
218
  exports.parseSubErrors = parseSubErrors;
271
- //# sourceMappingURL=parsed_error.cjs.map
219
+ //# sourceMappingURL=parsed_error.cjs.map
@@ -1 +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(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"],"names":["notEmpty","resourceTypeToString","resourceIdToString","z"],"mappings":";;;;;;AAAA;AAOA;AACM,MAAO,cAAe,SAAQ,KAAK,CAAA;AAChC,IAAA,KAAK;AACL,IAAA,WAAW;IAElB,WAAA,CAAY,YAAmB,EAAE,KAAY,EAAA;QAC3C,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,GAAGA,kBAAQ,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,CAACA,kBAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;AAElD,QAAA,IAAI,CAAC,KAAK,GAAG,KAAK;QAElB,MAAM,QAAQ,GACZ,aAAa,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,WAAW,KAAK;cACnD,KAAK,CAAC;AACR,cAAE,KAAK,CAAC,OAAO;AAEnB,QAAA,IAAI,CAAC,WAAW,GAAG,CAAA,gBAAA,EAAmB,QAAQ;;AAEhD,EAAA,IAAI,CAAC,KAAK;CACX;IACC;AACD;AAED;;;AAGG;AACG,MAAO,aAAc,SAAQ,KAAK,CAAA;AAKpB,IAAA,iBAAA;AAGA,IAAA,W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,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,GACtB,iFAAiF;IACnF,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;;;;;;;;;;;"}
1
+ {"version":3,"file":"parsed_error.cjs","names":["z"],"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(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":";;;;;;;AAQA,IAAa,iBAAb,cAAoC,MAAM;CACxC,AAAO;CACP,AAAO;CAEP,YAAY,cAAqB,OAAc;AAC7C,QAAM,mBAAmB,MAAM,WAAW,EAAE,OAAO,CAAC;AACpD,OAAK,OAAO;EAIZ,IAAI,iDAAiB,aAAa,MAAM;AACxC,UAAQ,MAAM,QAAQ,aAAa,SAAS,GAAG;AAC/C,UAAQ,MAAM,iDAAiB,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,AAAgB;CAEhB,YAEE,AAAgB,mBAGhB,AAAgB,aAGhB,AAAgB,WAGhB,AAAgB,QAGhB,AAAgB,WAChB,AAAgB,UAChB,AAAgB,cAChB;EACA,MAAM,gBA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M,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,90 +1,93 @@
1
- /** Pl Backend throws arbitrary errors, and we're trying to parse them here. */
2
- import type { ResourceId, ResourceType } from "@milaboratories/pl-client";
1
+ import { ResourceId, ResourceType } from "@milaboratories/pl-client";
2
+
3
+ //#region src/parsed_error.d.ts
3
4
  /** The error that comes from QuickJS. */
4
- export declare class PlQuickJSError extends Error {
5
- stack: string;
6
- fullMessage: string;
7
- constructor(quickJSError: Error, cause: Error);
5
+ declare class PlQuickJSError extends Error {
6
+ stack: string;
7
+ fullMessage: string;
8
+ constructor(quickJSError: Error, cause: Error);
8
9
  }
9
10
  /**
10
11
  * A parsed error from the Pl backend.
11
12
  * It contains several suberrors, which could be one or different causes of the error.
12
13
  */
13
- export declare class PlErrorReport extends Error {
14
- /** Full message from the Pl backend. */
15
- readonly rawBackendMessage: string;
16
- /** Either CID conflict or a error from controller. */
17
- readonly plErrorType: string;
18
- /** Parsed pl backend message that will be futher parsed into suberrors. */
19
- readonly plMessage: string;
20
- /** Could be several different errors, the name is from AggregateError. */
21
- readonly errors: PlCoreError[];
22
- /** Optional info about a resource where the error happened. */
23
- readonly fieldName?: string | undefined;
24
- readonly resource?: ResourceId | undefined;
25
- readonly resourceType?: ResourceType | undefined;
26
- readonly fullMessage: string;
27
- constructor(
28
- /** Full message from the Pl backend. */
29
- rawBackendMessage: string,
30
- /** Either CID conflict or a error from controller. */
31
- plErrorType: string,
32
- /** Parsed pl backend message that will be futher parsed into suberrors. */
33
- plMessage: string,
34
- /** Could be several different errors, the name is from AggregateError. */
35
- errors: PlCoreError[],
36
- /** Optional info about a resource where the error happened. */
37
- fieldName?: string | undefined, resource?: ResourceId | undefined, resourceType?: ResourceType | undefined);
14
+ declare class PlErrorReport extends Error {
15
+ /** Full message from the Pl backend. */
16
+ readonly rawBackendMessage: string;
17
+ /** Either CID conflict or a error from controller. */
18
+ readonly plErrorType: string;
19
+ /** Parsed pl backend message that will be futher parsed into suberrors. */
20
+ readonly plMessage: string;
21
+ /** Could be several different errors, the name is from AggregateError. */
22
+ readonly errors: PlCoreError[];
23
+ /** Optional info about a resource where the error happened. */
24
+ readonly fieldName?: string | undefined;
25
+ readonly resource?: ResourceId | undefined;
26
+ readonly resourceType?: ResourceType | undefined;
27
+ readonly fullMessage: string;
28
+ constructor(/** Full message from the Pl backend. */
29
+
30
+ rawBackendMessage: string, /** Either CID conflict or a error from controller. */
31
+
32
+ plErrorType: string, /** Parsed pl backend message that will be futher parsed into suberrors. */
33
+
34
+ plMessage: string, /** Could be several different errors, the name is from AggregateError. */
35
+
36
+ errors: PlCoreError[], /** Optional info about a resource where the error happened. */
37
+
38
+ fieldName?: string | undefined, resource?: ResourceId | undefined, resourceType?: ResourceType | undefined);
38
39
  }
39
40
  /**
40
41
  * A suberror of a parsed error.
41
42
  */
42
- export type PlCoreError = PlInternalError | PlTengoError | PlRunnerError | PlMonetizationError;
43
+ type PlCoreError = PlInternalError | PlTengoError | PlRunnerError | PlMonetizationError;
43
44
  /**
44
45
  * An general error when we couldn't parse the cause.
45
46
  */
46
- export declare class PlInternalError extends Error {
47
- readonly message: string;
48
- readonly fullMessage: string;
49
- constructor(message: string);
47
+ declare class PlInternalError extends Error {
48
+ readonly message: string;
49
+ readonly fullMessage: string;
50
+ constructor(message: string);
50
51
  }
51
52
  /**
52
53
  * Happens when workflow template panics.
53
54
  */
54
- export declare class PlTengoError extends Error {
55
- readonly rawBackendMessage: string;
56
- readonly templateName: string;
57
- readonly tengoMessage: string;
58
- readonly tengoStacktrace: string;
59
- readonly fullMessage: string;
60
- constructor(rawBackendMessage: string, templateName: string, tengoMessage: string, tengoStacktrace: string);
55
+ declare class PlTengoError extends Error {
56
+ readonly rawBackendMessage: string;
57
+ readonly templateName: string;
58
+ readonly tengoMessage: string;
59
+ readonly tengoStacktrace: string;
60
+ readonly fullMessage: string;
61
+ constructor(rawBackendMessage: string, templateName: string, tengoMessage: string, tengoStacktrace: string);
61
62
  }
62
63
  /**
63
64
  * Happens when a command fails to run.
64
65
  */
65
- export declare class PlRunnerError extends Error {
66
- readonly rawBackendMessage: string;
67
- readonly commandName: string;
68
- readonly exitCode: number;
69
- readonly stdout: string;
70
- readonly workingDirectory: string;
71
- readonly fullMessage: string;
72
- constructor(rawBackendMessage: string, commandName: string, exitCode: number, stdout: string, workingDirectory: string);
66
+ declare class PlRunnerError extends Error {
67
+ readonly rawBackendMessage: string;
68
+ readonly commandName: string;
69
+ readonly exitCode: number;
70
+ readonly stdout: string;
71
+ readonly workingDirectory: string;
72
+ readonly fullMessage: string;
73
+ constructor(rawBackendMessage: string, commandName: string, exitCode: number, stdout: string, workingDirectory: string);
73
74
  }
74
75
  /**
75
76
  * Happens when a monetization command fails to run.
76
77
  */
77
- export declare class PlMonetizationError extends PlRunnerError {
78
- readonly fullMessage: string;
79
- constructor(rawBackendMessage: string, commandName: string, exitCode: number, stdout: string, workingDirectory: string);
78
+ declare class PlMonetizationError extends PlRunnerError {
79
+ readonly fullMessage: string;
80
+ constructor(rawBackendMessage: string, commandName: string, exitCode: number, stdout: string, workingDirectory: string);
80
81
  }
81
82
  /**
82
83
  * Parses a Pl error and suberrors from the Pl backend.
83
84
  */
84
- export declare function parsePlError(error: string, resource?: ResourceId, resourceType?: ResourceType, field?: string): PlErrorReport;
85
+ declare function parsePlError(error: string, resource?: ResourceId, resourceType?: ResourceType, field?: string): PlErrorReport;
85
86
  /**
86
87
  * Reduces over the lines of the pl error message
87
88
  * to extract messages, and categorizes them.
88
89
  */
89
- export declare function parseSubErrors(message: string): PlCoreError[];
90
+ declare function parseSubErrors(message: string): PlCoreError[];
91
+ //#endregion
92
+ export { PlCoreError, PlErrorReport, PlInternalError, PlMonetizationError, PlQuickJSError, PlRunnerError, PlTengoError, parsePlError, parseSubErrors };
90
93
  //# sourceMappingURL=parsed_error.d.ts.map
@@ -1,161 +1,126 @@
1
- import { z } from 'zod';
2
- import { resourceTypeToString, resourceIdToString } from '@milaboratories/pl-client';
3
- import { notEmpty } from '@milaboratories/ts-helpers';
1
+ import { z } from "zod";
2
+ import { resourceIdToString, resourceTypeToString } from "@milaboratories/pl-client";
3
+ import { notEmpty } from "@milaboratories/ts-helpers";
4
4
 
5
+ //#region src/parsed_error.ts
5
6
  /** Pl Backend throws arbitrary errors, and we're trying to parse them here. */
6
7
  /** 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}
8
+ var PlQuickJSError = class extends Error {
9
+ stack;
10
+ fullMessage;
11
+ constructor(quickJSError, cause) {
12
+ super(`PlQuickJSError: ${cause.message}`, { cause });
13
+ this.name = "PlQuickJSError";
14
+ let stack = notEmpty(quickJSError.stack);
15
+ stack = stack.replace(quickJSError.message, "");
16
+ stack = stack.replace(notEmpty(cause.message), "");
17
+ this.stack = stack;
18
+ this.fullMessage = `PlQuickJSError: ${"fullMessage" in cause && typeof cause.fullMessage === "string" ? cause.fullMessage : cause.message}
23
19
  QuickJS stacktrace:
24
20
  ${this.stack}
25
21
  `;
26
- }
27
- }
22
+ }
23
+ };
28
24
  /**
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}
25
+ * A parsed error from the Pl backend.
26
+ * It contains several suberrors, which could be one or different causes of the error.
27
+ */
28
+ var PlErrorReport = class extends Error {
29
+ fullMessage;
30
+ constructor(rawBackendMessage, plErrorType, plMessage, errors, fieldName, resource, resourceType) {
31
+ const errorMessages = errors.map((e) => e.message).join("\n\n");
32
+ const errorFullMessages = errors.map((e) => e.fullMessage).join("\n\n");
33
+ super(`PlErrorReport: ${errorMessages}`);
34
+ this.rawBackendMessage = rawBackendMessage;
35
+ this.plErrorType = plErrorType;
36
+ this.plMessage = plMessage;
37
+ this.errors = errors;
38
+ this.fieldName = fieldName;
39
+ this.resource = resource;
40
+ this.resourceType = resourceType;
41
+ this.name = "PlErrorReport";
42
+ this.fullMessage = `PlErrorReport: resource: ${this.resourceType ? `${resourceTypeToString(this.resourceType)},` : ""} ${this.resource ? resourceIdToString(this.resource) : ""}${this.fieldName ? `/${this.fieldName}` : ""}
43
+ ${this.plErrorType ? `error type: ${this.plErrorType}` : ""}
69
44
  ${errorFullMessages}
70
45
  `;
71
- }
72
- }
46
+ }
47
+ };
73
48
  /**
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
- }
49
+ * An general error when we couldn't parse the cause.
50
+ */
51
+ var PlInternalError = class extends Error {
52
+ fullMessage;
53
+ constructor(message) {
54
+ super(message);
55
+ this.message = message;
56
+ this.name = "PlInternalError";
57
+ this.fullMessage = `PlInternalError: ${message}`;
58
+ }
59
+ };
86
60
  /**
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:
61
+ * Happens when workflow template panics.
62
+ */
63
+ var PlTengoError = class extends Error {
64
+ fullMessage;
65
+ constructor(rawBackendMessage, templateName, tengoMessage, tengoStacktrace) {
66
+ const msg = `PlTengoError:
97
67
  message:
98
68
  ${tengoMessage}
99
69
  template: ${templateName}
100
70
  tengo stacktrace:
101
71
  ${tengoStacktrace}
102
72
  `;
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}
73
+ super(msg);
74
+ this.rawBackendMessage = rawBackendMessage;
75
+ this.templateName = templateName;
76
+ this.tengoMessage = tengoMessage;
77
+ this.tengoStacktrace = tengoStacktrace;
78
+ this.name = "PlTengoError";
79
+ this.fullMessage = `${msg}
110
80
  raw message:
111
81
  ${this.rawBackendMessage}
112
82
  `;
113
- }
114
- }
83
+ }
84
+ };
115
85
  /**
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:
86
+ * Happens when a command fails to run.
87
+ */
88
+ var PlRunnerError = class extends Error {
89
+ fullMessage;
90
+ constructor(rawBackendMessage, commandName, exitCode, stdout, workingDirectory) {
91
+ const msg = `PlRunnerError:
127
92
  command: ${commandName}
128
93
  exit code: ${exitCode}
129
94
  working directory: ${workingDirectory}
130
95
  stdout:
131
96
  ${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 = `
97
+ super(msg);
98
+ this.rawBackendMessage = rawBackendMessage;
99
+ this.commandName = commandName;
100
+ this.exitCode = exitCode;
101
+ this.stdout = stdout;
102
+ this.workingDirectory = workingDirectory;
103
+ this.name = "PlRunnerError";
104
+ this.fullMessage = `
140
105
  ${msg}
141
106
  raw message:
142
107
  ${this.rawBackendMessage}
143
108
  `;
144
- }
145
- }
109
+ }
110
+ };
146
111
  /**
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:
112
+ * Happens when a monetization command fails to run.
113
+ */
114
+ var PlMonetizationError = class extends PlRunnerError {
115
+ fullMessage;
116
+ constructor(rawBackendMessage, commandName, exitCode, stdout, workingDirectory) {
117
+ super(rawBackendMessage, commandName, exitCode, stdout, workingDirectory);
118
+ const msg = `Monetizaiton error:
154
119
  ${this.stdout}
155
120
  `;
156
- this.message = msg;
157
- this.name = "PlMonetizationError";
158
- this.fullMessage = `
121
+ this.message = msg;
122
+ this.name = "PlMonetizationError";
123
+ this.fullMessage = `
159
124
  ${msg}
160
125
  command: ${this.commandName}
161
126
  exit code: ${this.exitCode}
@@ -164,99 +129,84 @@ working directory: ${this.workingDirectory}
164
129
  raw message:
165
130
  ${this.rawBackendMessage}
166
131
  `;
167
- }
168
- }
132
+ }
133
+ };
169
134
  /**
170
- * How the Pl backend represents an error.
171
- */
172
- const backendErrorSchema = z
173
- .object({
174
- errorType: z.string().default(""),
175
- message: z.string(),
176
- })
177
- .passthrough();
135
+ * How the Pl backend represents an error.
136
+ */
137
+ const backendErrorSchema = z.object({
138
+ errorType: z.string().default(""),
139
+ message: z.string()
140
+ }).passthrough();
178
141
  /**
179
- * Parses a Pl error and suberrors from the Pl backend.
180
- */
142
+ * Parses a Pl error and suberrors from the Pl backend.
143
+ */
181
144
  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);
145
+ const parsed = backendErrorSchema.safeParse(JSON.parse(error));
146
+ if (!parsed.success) throw new Error(`parsePlError: failed to parse the message, got ${error}`);
147
+ const errors = parseSubErrors(parsed.data.message);
148
+ return new PlErrorReport(error, parsed.data.errorType, parsed.data.message, errors, field, resource, resourceType);
188
149
  }
189
150
  /**
190
- * Reduces over the lines of the pl error message
191
- * to extract messages, and categorizes them.
192
- */
151
+ * Reduces over the lines of the pl error message
152
+ * to extract messages, and categorizes them.
153
+ */
193
154
  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;
155
+ const state = {
156
+ stage: "initial",
157
+ value: [],
158
+ result: []
159
+ };
160
+ for (const line of message.split("\n")) {
161
+ if (state.stage == "initial") state.stage = "path";
162
+ else if (state.stage == "path" && line.startsWith("---")) {} else if (state.stage == "path" && !isPath(line)) state.stage = "message";
163
+ else if (state.stage == "message" && isPath(line)) {
164
+ state.stage = "path";
165
+ const text = state.value.join("\n");
166
+ state.result.push(parseCoreError(text));
167
+ state.value = [];
168
+ }
169
+ state.value.push(line);
170
+ }
171
+ const text = state.value.join("\n");
172
+ state.result.push(parseCoreError(text));
173
+ return state.result;
221
174
  }
222
175
  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;
176
+ for (const fieldType of [
177
+ "U",
178
+ "I",
179
+ "O",
180
+ "S",
181
+ "OTW",
182
+ "D",
183
+ "MTW"
184
+ ]) if (line.startsWith(`[${fieldType}]`)) return true;
185
+ return false;
228
186
  }
229
187
  /**
230
- * Parses a suberror from the Pl backend.
231
- */
188
+ * Parses a suberror from the Pl backend.
189
+ */
232
190
  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);
191
+ const match = message.match(/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]*)/);
192
+ if (match) {
193
+ const workingDirectory = match[1];
194
+ const command = match[2];
195
+ const exitCode = parseInt(match[3], 10);
196
+ const stdout = match[4].trim();
197
+ if (command.endsWith(`mnz-client`) && exitCode == 1) return new PlMonetizationError(message, command, exitCode, stdout, workingDirectory);
198
+ return new PlRunnerError(message, command, exitCode, stdout, workingDirectory);
199
+ }
200
+ const workflowMatch = message.match(/cannot eval code: cannot eval template: template: (.+)\n\t(.*?)\n\t(at [\s\S]*)/);
201
+ if (workflowMatch) {
202
+ const templateName = workflowMatch[1];
203
+ const errorMessage = workflowMatch[2];
204
+ const stackTrace = workflowMatch[3];
205
+ return new PlTengoError(message, templateName, errorMessage, stackTrace);
206
+ }
207
+ return new PlInternalError(message);
259
208
  }
260
209
 
210
+ //#endregion
261
211
  export { PlErrorReport, PlInternalError, PlMonetizationError, PlQuickJSError, PlRunnerError, PlTengoError, parsePlError, parseSubErrors };
262
- //# sourceMappingURL=parsed_error.js.map
212
+ //# sourceMappingURL=parsed_error.js.map
@@ -1 +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(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"],"names":[],"mappings":";;;;AAAA;AAOA;AACM,MAAO,cAAe,SAAQ,KAAK,CAAA;AAChC,IAAA,KAAK;AACL,IAAA,WAAW;IAElB,WAAA,CAAY,YAAmB,EAAE,KAAY,EAAA;QAC3C,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,GACZ,aAAa,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,WAAW,KAAK;cACnD,KAAK,CAAC;AACR,cAAE,KAAK,CAAC,OAAO;AAEnB,QAAA,IAAI,CAAC,WAAW,GAAG,CAAA,gBAAA,EAAmB,QAAQ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,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,gBAAgB,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,GACtB,iFAAiF;IACnF,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;;;;"}
1
+ {"version":3,"file":"parsed_error.js","names":[],"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(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":";;;;;;;AAQA,IAAa,iBAAb,cAAoC,MAAM;CACxC,AAAO;CACP,AAAO;CAEP,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,AAAgB;CAEh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,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milaboratories/pl-errors",
3
- "version": "1.1.69",
3
+ "version": "1.1.71",
4
4
  "description": "Parsing errors from Pl backend",
5
5
  "files": [
6
6
  "./dist/**/*",
@@ -18,17 +18,17 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "zod": "~3.23.8",
21
- "@milaboratories/pl-client": "2.17.7",
22
- "@milaboratories/ts-helpers": "1.7.2"
21
+ "@milaboratories/pl-client": "2.17.9",
22
+ "@milaboratories/ts-helpers": "1.7.3"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@vitest/coverage-istanbul": "^4.0.18",
26
- "typescript": "~5.6.3",
26
+ "typescript": "~5.9.3",
27
27
  "vitest": "^4.0.18",
28
- "@milaboratories/ts-builder": "1.2.11",
29
- "@milaboratories/build-configs": "1.5.0",
30
- "@milaboratories/pl-error-like": "1.12.8",
31
- "@milaboratories/ts-configs": "1.2.1"
28
+ "@milaboratories/build-configs": "1.5.2",
29
+ "@milaboratories/pl-error-like": "1.12.9",
30
+ "@milaboratories/ts-builder": "1.2.14",
31
+ "@milaboratories/ts-configs": "1.2.2"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "ts-builder build --target node",
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"parsed_error.d.ts","sourceRoot":"","sources":["../src/parsed_error.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAG/E,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAI1E,yCAAyC;AACzC,qBAAa,cAAe,SAAQ,KAAK;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;gBAEf,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;CAsB9C;AAED;;;GAGG;AACH,qBAAa,aAAc,SAAQ,KAAK;IAIpC,wCAAwC;aACxB,iBAAiB,EAAE,MAA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