Skip to content

Commit 19a8035

Browse files
committed
fixed rust unwrap err parsing
1 parent f27bea8 commit 19a8035

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

packages/js/core/src/types/WrapError.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class WrapError extends Error {
8787

8888
private static re = new RegExp(
8989
[
90-
/^(?:[A-Za-z_: ]*; )?WrapError: (?<reason>(?:.|\r|\n)*)/.source,
90+
/^(?:[A-Za-z_:()` ]*;? "?)?WrapError: (?<reason>(?:.|\r|\n)*)/.source,
9191
// there is some padding added to the number of words expected in an error code
9292
/(?:\r\n|\r|\n)code: (?<code>1?[0-9]{1,2}|2[0-4][0-9]|25[0-5]) (?:[A-Z]+ ?){1,5}/
9393
.source,
@@ -99,12 +99,14 @@ export class WrapError extends Error {
9999
.source,
100100
/(?:(?:\r\n|\r|\n)uriResolutionStack: (?<resolutionStack>\[(?:.|\r|\n)+]))?/
101101
.source,
102-
/(?:(?:\r\n|\r|\n){2}This exception was caused by the following exception:(?:\r\n|\r|\n)(?<cause>(?:.|\r|\n)+))?$/
102+
/(?:(?:\r\n|\r|\n){2}This exception was caused by the following exception:(?:\r\n|\r|\n)(?<cause>(?:.|\r|\n)+))?/
103103
.source,
104+
/"?$/.source,
104105
].join("")
105106
);
106107

107108
static parse(error: string): WrapError | undefined {
109+
error = WrapError.sanitizeUnwrappedRustResult(error);
108110
const delim = "\n\nAnother exception was encountered during execution:\n";
109111
const errorStrings = error.split(delim);
110112

@@ -137,6 +139,19 @@ export class WrapError extends Error {
137139
return `${this.name}: ${this.message}`;
138140
}
139141

142+
// remove escape characters that may have been added by Rust
143+
private static sanitizeUnwrappedRustResult(error: string): string {
144+
if (
145+
error.startsWith(
146+
'__wrap_abort: called `Result::unwrap()` on an `Err` value: "'
147+
)
148+
) {
149+
error = error.replace(/\\"/g, '"');
150+
error = error.replace(/\\n/g, "\n");
151+
}
152+
return error;
153+
}
154+
140155
// parse a single WrapError, where the 'prev' property is undefined
141156
private static _parse(
142157
error: string

0 commit comments

Comments
 (0)