Skip to content

Commit

Permalink
Also warn to console
Browse files Browse the repository at this point in the history
  • Loading branch information
WardBrian committed Aug 13, 2024
1 parent 576d2c2 commit a76954a
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions gui/src/app/CompileContext/compileStanProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const compileStanProgram = async (
stanProgram: string,
onStatus: (s: string) => void,
): Promise<{ mainJsUrl?: string }> => {
const setStatusAndWarn = (msg: string) => {
onStatus(msg);
console.warn(msg);
};

try {
onStatus("checking cache");
const downloadMainJsUrlFromCache = await checkMainJsUrlCache(
Expand All @@ -27,13 +32,15 @@ const compileStanProgram = async (
},
});
if (!initiation.ok) {
onStatus(`failed to initiate job: ${await messageOrStatus(initiation)}`);
setStatusAndWarn(
`failed to initiate job: ${await messageOrStatus(initiation)}`,
);
return {};
}
const resp = await initiation.json();
const job_id = resp.job_id;
if (!job_id) {
onStatus(`failed to initiate job: ${JSON.stringify(resp)}`);
setStatusAndWarn(`failed to initiate job: ${JSON.stringify(resp)}`);
return {};
}

Expand All @@ -47,7 +54,9 @@ const compileStanProgram = async (
body: stanProgram,
});
if (!upload.ok) {
onStatus(`failed to upload file: ${await messageOrStatus(upload)}`);
setStatusAndWarn(
`failed to upload file: ${await messageOrStatus(upload)}`,
);
return {};
}
onStatus("file uploaded successfully");
Expand All @@ -61,7 +70,9 @@ const compileStanProgram = async (
},
});
if (!runCompile.ok) {
onStatus(`failed to compile: ${await messageOrStatus(runCompile)}`);
setStatusAndWarn(
`failed to compile: ${await messageOrStatus(runCompile)}`,
);
return {};
}

Expand All @@ -73,7 +84,7 @@ const compileStanProgram = async (
onStatus("Checking download of main.js");
const downloadCheck = await fetch(mainJsUrl);
if (!downloadCheck.ok) {
onStatus(
setStatusAndWarn(
`failed to download main.js: ${await messageOrStatus(downloadCheck)}`,
);
return {};
Expand All @@ -82,7 +93,7 @@ const compileStanProgram = async (
onStatus("compiled");
return { mainJsUrl };
} catch (e) {
onStatus(`failed to compile: ${e}`);
setStatusAndWarn(`failed to compile: ${e}`);
return {};
}
};
Expand Down

0 comments on commit a76954a

Please sign in to comment.