mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
add fallback shell configs
This commit is contained in:
parent
36ff6e9b95
commit
d661c4d18c
2 changed files with 30 additions and 4 deletions
|
|
@ -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');
|
||||
|
|
|
|||
25
app/utils/shell-fallback.ts
Normal file
25
app/utils/shell-fallback.ts
Normal file
|
|
@ -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;
|
||||
};
|
||||
Loading…
Reference in a new issue