Skip to content

Commit 2fa1cf2

Browse files
committed
added check for invalid source code
1 parent 75a4cee commit 2fa1cf2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pages/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ const Home: NextPage = () => {
1818
setByteCode(() => data.byteCode);
1919
setAbi(() => JSON.stringify(data.abi));
2020
})
21-
.catch(console.error)
21+
.catch(err => {
22+
alert(err);
23+
console.error(err);
24+
})
2225
.finally(() => {
2326
button.disabled = false;
2427
});

src/sol/compiler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const compile = (contractCode: string): Promise<ContractData[]> => {
2828
worker.onmessage = function (e: any) {
2929
const output = e.data.output;
3030
const result = [];
31+
if (!output.contracts) {
32+
reject("Invalid source code");
33+
return;
34+
}
3135
for (const contractName in output.contracts['contract']) {
3236
const contract = output.contracts['contract'][contractName];
3337
result.push({

0 commit comments

Comments
 (0)