From d661c4d18c4455418a249cdefffc2dd09cc1685c Mon Sep 17 00:00:00 2001 From: Labhansh Agrawal Date: Wed, 26 Jul 2023 12:18:20 +0530 Subject: [PATCH] add fallback shell configs --- app/session.ts | 9 +++++---- app/utils/shell-fallback.ts | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 app/utils/shell-fallback.ts diff --git a/app/session.ts b/app/session.ts index 74d9d72bb370..8a44466fff26 100644 --- a/app/session.ts +++ b/app/session.ts @@ -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( @@ -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'); diff --git a/app/utils/shell-fallback.ts b/app/utils/shell-fallback.ts new file mode 100644 index 000000000000..0eb7df4bd12d --- /dev/null +++ b/app/utils/shell-fallback.ts @@ -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; +};