Skip to content

Commit

Permalink
fix: check for failed state during session log stream to prevent unbo…
Browse files Browse the repository at this point in the history
…unded loop (#564)

Also adds enhanced error dialog when run errors are Compute Error representations
  • Loading branch information
smorrisj authored Oct 24, 2023
1 parent 48848fa commit b70da81
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
51 changes: 46 additions & 5 deletions client/src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {
wrapCodeWithOutputHtml,
} from "../components/utils/sasCode";
import { isOutputHtmlEnabled } from "../components/utils/settings";
import { OnLogFn, RunResult, getSession } from "../connection";
import {
ErrorRepresentation,
OnLogFn,
RunResult,
getSession,
} from "../connection";
import { profileConfig, switchProfile } from "./profile";

interface FoldingBlock {
Expand Down Expand Up @@ -170,10 +175,7 @@ const _run = async (selected = false, uri?: Uri) => {

await runCode(selected, uri)
.catch((err) => {
console.dir(err);
window.showErrorMessage(
err.response?.data ? JSON.stringify(err.response.data) : err.message,
);
onRunError(err);
})
.finally(() => {
running = false;
Expand Down Expand Up @@ -235,3 +237,42 @@ export async function runTask(
messageEmitter.fire(`${l10n.t("SAS code running...")}\r\n`);
return cancelled ? undefined : session.run(code);
}

const isErrorRep = (err: unknown): err is ErrorRepresentation => {
if (
err &&
typeof err === "object" &&
"message" in err &&
"details" in err &&
Array.isArray(err.details) &&
"errorCode" in err
) {
return true;
}
return false;
};

const onRunError = (err) => {
console.dir(err);

if (err.response) {
// The request was made and we got a status code that falls out side of the 2xx range
const errorData = err.response.data;

if (isErrorRep(errorData)) {
//errorData is an error representation, extract out the details to show a better message
const details = errorData.details;
const options = {
modal: true,
detail: details.join("\n"),
};
window.showErrorMessage(errorData.message, options);
} else {
window.showErrorMessage(err.message);
}
} else {
// Either the request was made but no response was received, or
// there was an issue in the request setup itself, just show the message
window.showErrorMessage(err.message);
}
};
2 changes: 2 additions & 0 deletions client/src/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { getSession as getCOMSession } from "./com";
import { Config as RestConfig, getSession as getRestSession } from "./rest";
import {
Error2 as ComputeError,
LogLine as ComputeLogLine,
LogLineTypeEnum as ComputeLogLineTypeEnum,
} from "./rest/api/compute";
Expand All @@ -20,6 +21,7 @@ import { getSession as getSSHSession } from "./ssh";

let profileConfig: ProfileConfig;

export type ErrorRepresentation = ComputeError;
export type LogLine = ComputeLogLine;
export type LogLineTypeEnum = ComputeLogLineTypeEnum;
export type OnLogFn = (logs: LogLine[]) => void;
Expand Down
1 change: 1 addition & 0 deletions client/src/connection/rest/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export class ComputeSession extends Compute {
"warning",
"completed",
"idle",
"failed",
];

while (states.indexOf(state) === -1) {
Expand Down

0 comments on commit b70da81

Please sign in to comment.