Skip to content

Commit

Permalink
Support calculation errors in build
Browse files Browse the repository at this point in the history
  • Loading branch information
beliolfa committed Oct 2, 2024
1 parent 646a6fd commit 9ca2ba5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/lib/EnvelopeEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@
const result = await actions.sign(builderContext);
dispatch("sign", result);
// There is no need to set the state here as it is
// handled by setState watcher. We return the value
// to inform external caller
if (result?.error) {
displayAllErrors(result?.error?.message || "");
return "errored";
}
return "signed"
};
export const validate = async () => {
Expand Down
7 changes: 2 additions & 5 deletions src/lib/editor/code/EditorCode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import SuccessIcon from "$lib/ui/icons/SuccessIcon.svelte";
import LightbulbIcon from "$lib/ui/icons/LightbulbIcon.svelte";
import { getBuilderContext } from "$lib/store/builder.js";
import { getErrorString } from "$lib/helpers";
import { getGOBLErrorMessage } from "$lib/helpers";
let monaco: typeof Monaco;
Expand Down Expand Up @@ -137,10 +137,7 @@
return;
}
const parsedError = JSON.parse(goblErr.message);
const errorString =
parsedError.key === "validation" ? getErrorString(parsedError.fields?.doc) : parsedError.message;
const errorString = getGOBLErrorMessage(goblErr.message);
const errorsArr = errorString.split(" / ");
Expand Down
13 changes: 11 additions & 2 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,18 @@ export function showErrorToast(description: string) {
});
}

export function getGOBLErrorMessage(message: string) {
const parsedError = JSON.parse(message);

return parsedError.key === "validation"
? getErrorString(parsedError.fields?.doc)
: parsedError.key === "calculation"
? getErrorString(parsedError.fields)
: parsedError.message;
}

export async function displayAllErrors(error: string) {
const parsedError = JSON.parse(error);
const errorMessage = parsedError.key === "validation" ? getErrorString(parsedError.fields?.doc) : parsedError.message;
const errorMessage = getGOBLErrorMessage(error);
const errorsArr = errorMessage.split(" / ");

for (let i = 0; i < errorsArr.length; i++) {
Expand Down

0 comments on commit 9ca2ba5

Please sign in to comment.