Skip to content

Commit

Permalink
add fallback shell configs
Browse files Browse the repository at this point in the history
  • Loading branch information
LabhanshAgrawal committed Jul 26, 2023
1 parent 36ff6e9 commit d661c4d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
9 changes: 5 additions & 4 deletions app/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as config from './config';
import {cliScriptPath} from './config/paths';
import {productName, version} from './package.json';
import {getDecoratedEnv} from './plugins';
import {getFallBackShellConfig} from './utils/shell-fallback';

const createNodePtyError = () =>
new Error(
Expand Down Expand Up @@ -183,16 +184,16 @@ export default class Session extends EventEmitter {
// fall back to default shell config if the shell exits within 1 sec with non zero exit code
// this will inform users in case there are errors in the config instead of instant exit
const runDuration = new Date().getTime() - this.initTimestamp;
if (e.exitCode > 0 && runDuration < 1000) {
const defaultShellConfig = {shell: defaultShell, shellArgs: defaultShellArgs};
const fallBackShellConfig = getFallBackShellConfig(shell, shellArgs, defaultShell, defaultShellArgs);
if (e.exitCode > 0 && runDuration < 1000 && fallBackShellConfig) {
const msg = `
shell exited in ${runDuration} ms with exit code ${e.exitCode}
please check the shell config: ${JSON.stringify({shell, shellArgs}, undefined, 2)}
fallback to default shell config: ${JSON.stringify(defaultShellConfig, undefined, 2)}
using fallback shell config: ${JSON.stringify(fallBackShellConfig, undefined, 2)}
`;
console.warn(msg);
this.batcher?.write(msg.replace(/\n/g, '\r\n'));
this.init({uid, rows, cols, cwd, ...defaultShellConfig, profile});
this.init({uid, rows, cols, cwd, ...fallBackShellConfig, profile});
} else {
this.ended = true;
this.emit('exit');
Expand Down
25 changes: 25 additions & 0 deletions app/utils/shell-fallback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const getFallBackShellConfig = (
shell: string,
shellArgs: string[],
defaultShell: string,
defaultShellArgs: string[]
): {
shell: string;
shellArgs: string[];
} | null => {
if (shellArgs.length > 0) {
return {
shell,
shellArgs: []
};
}

if (shell != defaultShell) {
return {
shell: defaultShell,
shellArgs: defaultShellArgs
};
}

return null;
};

0 comments on commit d661c4d

Please sign in to comment.