Error Handling (wasm call)
When a compilation error occurs, it returns an error message with the following json structure w/ prefix([Error]:):
{
"line": number,
"column": number,
"length": number,
"message": string,
"found": string,
}
EX)
[Error]:{"line":24, "column":10, "length":1, "message":"Expected -> or ~>", "found":"^"}
Therefore, you can handle it as follows in your TypeScript application:
parsePlayBookError.ts
export interface PlayBookError {
line: number;
column: number;
length: number;
message: string;
found: string;
}
export function parsePlayBookError(
errorString: string,
): PlayBookError | undefined {
const prefix = "[Error]:";
if (errorString.startsWith(prefix)) {
try {
const jsonString = errorString.substring(prefix.length);
return JSON.parse(jsonString) as PlayBookError;
} catch (e) {
return undefined;
}
}
return undefined;
}