@ar.io/sdk 3.1.0-alpha.7 → 3.1.0-alpha.8
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.
|
@@ -57,17 +57,15 @@ class AOProcess {
|
|
|
57
57
|
this.logger.debug(`Read interaction result`, {
|
|
58
58
|
result,
|
|
59
59
|
});
|
|
60
|
+
const error = errorMessageFromOutput(result);
|
|
61
|
+
if (error !== undefined) {
|
|
62
|
+
throw new Error(error);
|
|
63
|
+
}
|
|
60
64
|
if (result.Messages === undefined || result.Messages.length === 0) {
|
|
61
65
|
this.logger.debug(`Process ${this.processId} does not support provided action.`, result, tags);
|
|
62
66
|
throw new Error(`Process ${this.processId} does not support provided action.`);
|
|
63
67
|
}
|
|
64
|
-
const tagsOutput = result.Messages?.[0]?.Tags;
|
|
65
68
|
const messageData = result.Messages?.[0]?.Data;
|
|
66
|
-
const errorData = result.Error;
|
|
67
|
-
const error = errorData || tagsOutput?.find((tag) => tag.name === 'Error')?.value;
|
|
68
|
-
if (error) {
|
|
69
|
-
throw new Error(`${error}${messageData ? `: ${messageData}` : ''}`);
|
|
70
|
-
}
|
|
71
69
|
// return undefined if no data is returned
|
|
72
70
|
if (this.isMessageDataEmpty(messageData)) {
|
|
73
71
|
return undefined;
|
|
@@ -78,7 +76,7 @@ class AOProcess {
|
|
|
78
76
|
catch (e) {
|
|
79
77
|
attempts++;
|
|
80
78
|
this.logger.debug(`Read attempt ${attempts} failed`, {
|
|
81
|
-
error: e,
|
|
79
|
+
error: e instanceof Error ? e.message : e,
|
|
82
80
|
tags,
|
|
83
81
|
});
|
|
84
82
|
lastError = e;
|
|
@@ -125,11 +123,8 @@ class AOProcess {
|
|
|
125
123
|
messageId,
|
|
126
124
|
processId: this.processId,
|
|
127
125
|
});
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')
|
|
131
|
-
?.value;
|
|
132
|
-
if (error) {
|
|
126
|
+
const error = errorMessageFromOutput(output);
|
|
127
|
+
if (error !== undefined) {
|
|
133
128
|
throw new error_js_1.WriteInteractionError(error);
|
|
134
129
|
}
|
|
135
130
|
// check if there are any Messages in the output
|
|
@@ -177,3 +172,20 @@ class AOProcess {
|
|
|
177
172
|
}
|
|
178
173
|
}
|
|
179
174
|
exports.AOProcess = AOProcess;
|
|
175
|
+
function errorMessageFromOutput(output) {
|
|
176
|
+
const errorData = output.Error;
|
|
177
|
+
if (errorData !== undefined) {
|
|
178
|
+
// TODO: Could clean this one up too, current error is verbose, but not always deterministic for parsing
|
|
179
|
+
// Throw the whole raw error if AO process level error
|
|
180
|
+
return errorData;
|
|
181
|
+
}
|
|
182
|
+
const error = output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
|
|
183
|
+
if (error !== undefined) {
|
|
184
|
+
// from [string "aos"]:6846: Name is already registered
|
|
185
|
+
const lineNumber = error.match(/\d+/)?.[0];
|
|
186
|
+
const message = error.replace(/\[string "aos"\]:\d+:/, '');
|
|
187
|
+
// to more user friendly: Name is already registered (line 6846)
|
|
188
|
+
return `${message} (line ${lineNumber})`.trim();
|
|
189
|
+
}
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
package/lib/cjs/version.js
CHANGED
|
@@ -54,17 +54,15 @@ export class AOProcess {
|
|
|
54
54
|
this.logger.debug(`Read interaction result`, {
|
|
55
55
|
result,
|
|
56
56
|
});
|
|
57
|
+
const error = errorMessageFromOutput(result);
|
|
58
|
+
if (error !== undefined) {
|
|
59
|
+
throw new Error(error);
|
|
60
|
+
}
|
|
57
61
|
if (result.Messages === undefined || result.Messages.length === 0) {
|
|
58
62
|
this.logger.debug(`Process ${this.processId} does not support provided action.`, result, tags);
|
|
59
63
|
throw new Error(`Process ${this.processId} does not support provided action.`);
|
|
60
64
|
}
|
|
61
|
-
const tagsOutput = result.Messages?.[0]?.Tags;
|
|
62
65
|
const messageData = result.Messages?.[0]?.Data;
|
|
63
|
-
const errorData = result.Error;
|
|
64
|
-
const error = errorData || tagsOutput?.find((tag) => tag.name === 'Error')?.value;
|
|
65
|
-
if (error) {
|
|
66
|
-
throw new Error(`${error}${messageData ? `: ${messageData}` : ''}`);
|
|
67
|
-
}
|
|
68
66
|
// return undefined if no data is returned
|
|
69
67
|
if (this.isMessageDataEmpty(messageData)) {
|
|
70
68
|
return undefined;
|
|
@@ -75,7 +73,7 @@ export class AOProcess {
|
|
|
75
73
|
catch (e) {
|
|
76
74
|
attempts++;
|
|
77
75
|
this.logger.debug(`Read attempt ${attempts} failed`, {
|
|
78
|
-
error: e,
|
|
76
|
+
error: e instanceof Error ? e.message : e,
|
|
79
77
|
tags,
|
|
80
78
|
});
|
|
81
79
|
lastError = e;
|
|
@@ -122,11 +120,8 @@ export class AOProcess {
|
|
|
122
120
|
messageId,
|
|
123
121
|
processId: this.processId,
|
|
124
122
|
});
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')
|
|
128
|
-
?.value;
|
|
129
|
-
if (error) {
|
|
123
|
+
const error = errorMessageFromOutput(output);
|
|
124
|
+
if (error !== undefined) {
|
|
130
125
|
throw new WriteInteractionError(error);
|
|
131
126
|
}
|
|
132
127
|
// check if there are any Messages in the output
|
|
@@ -173,3 +168,20 @@ export class AOProcess {
|
|
|
173
168
|
throw lastError;
|
|
174
169
|
}
|
|
175
170
|
}
|
|
171
|
+
function errorMessageFromOutput(output) {
|
|
172
|
+
const errorData = output.Error;
|
|
173
|
+
if (errorData !== undefined) {
|
|
174
|
+
// TODO: Could clean this one up too, current error is verbose, but not always deterministic for parsing
|
|
175
|
+
// Throw the whole raw error if AO process level error
|
|
176
|
+
return errorData;
|
|
177
|
+
}
|
|
178
|
+
const error = output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
|
|
179
|
+
if (error !== undefined) {
|
|
180
|
+
// from [string "aos"]:6846: Name is already registered
|
|
181
|
+
const lineNumber = error.match(/\d+/)?.[0];
|
|
182
|
+
const message = error.replace(/\[string "aos"\]:\d+:/, '');
|
|
183
|
+
// to more user friendly: Name is already registered (line 6846)
|
|
184
|
+
return `${message} (line ${lineNumber})`.trim();
|
|
185
|
+
}
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
package/lib/esm/version.js
CHANGED
package/lib/types/version.d.ts
CHANGED