Skip to content

Commit

Permalink
fix: show SyntaxError line/column in alert
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Sep 24, 2024
1 parent 0ff80b6 commit 36079c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 1 addition & 2 deletions apps/playground/src/context/DeobfuscateContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ function useProviderValue(props: Props) {
props.onResult(data);
} else if (data.type === 'error') {
setDeobfuscating(false);
setAlert(data.error.toString());
console.error(data.error);
setAlert(data.error.name + ': ' + data.error.message);
}
};
}
Expand Down
15 changes: 14 additions & 1 deletion apps/playground/src/webcrack.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,20 @@ self.onmessage = async ({ data }: MessageEvent<WorkerRequest>) => {

postMessage({ type: 'result', code: result.code, files });
} catch (error) {
postMessage({ type: 'error', error: error as Error });
console.error(error);
// It has to be manually cloned because postMessage/structuredClone
// doesn't retain additional properties like `.loc` in babel SyntaxErrors
postMessage({
type: 'error',
error:
error instanceof Error
? {
...error,
name: error.name,
message: error.message,
}
: (error as Error),
});
}
};

Expand Down

0 comments on commit 36079c2

Please sign in to comment.