Skip to content

Commit 9a36796

Browse files
denishacquinDen
and
Den
authored
fix: improve contract error handling (#733)
* prevent errors from covering code * extract relevant info from compilation errors * compact finality window field * increase error height * support basic error messages --------- Co-authored-by: Den <den@Deniss-MacBook-Pro.local>
1 parent 3f0aecb commit 9a36796

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

frontend/src/components/Simulator/ContractsPanel.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const showHome = computed(() => store.currentContractId === '');
3131

3232
<div
3333
v-if="!!error"
34-
class="w-full shrink-0 bg-red-500 px-2 py-1 text-sm text-white"
34+
class="max-h-[160px] w-full shrink-0 overflow-y-auto whitespace-pre-wrap bg-red-500 bg-opacity-80 px-2 py-1 text-xs text-white"
3535
>
3636
{{ error }}
3737
</div>

frontend/src/hooks/useContractQueries.ts

+21-7
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,29 @@ export function useContractQueries() {
6767
return mockContractSchema;
6868
}
6969

70-
const result = await genlayer.client?.getContractSchemaForCode(
71-
contract.value?.content ?? '',
72-
);
73-
74-
schema.value = result;
75-
76-
return schema.value;
70+
try {
71+
const result = await genlayer.client?.getContractSchemaForCode(
72+
contract.value?.content ?? '',
73+
);
74+
75+
schema.value = result;
76+
return schema.value;
77+
} catch (error: any) {
78+
const errorMessage = extractErrorMessage(error);
79+
throw new Error(errorMessage);
80+
}
7781
}
7882

83+
const extractErrorMessage = (error: any) => {
84+
try {
85+
const details = JSON.parse(error.details);
86+
const message = details.data.error.args[1].stderr;
87+
return message;
88+
} catch (err) {
89+
return error.details;
90+
}
91+
};
92+
7993
const isDeploying = ref(false);
8094

8195
async function deployContract(

frontend/src/views/Simulator/RunDebugView.vue

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const isFinalityWindowValid = computed(() => {
7171
testId="input-finalityWindow"
7272
:disabled="false"
7373
class="w-20"
74+
tiny
7475
/>
7576
</div>
7677

0 commit comments

Comments
 (0)