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 {cliScriptPath} from './config/paths';
|
||||||
import {productName, version} from './package.json';
|
import {productName, version} from './package.json';
|
||||||
import {getDecoratedEnv} from './plugins';
|
import {getDecoratedEnv} from './plugins';
|
||||||
|
import {getFallBackShellConfig} from './utils/shell-fallback';
|
||||||
|
|
||||||
const createNodePtyError = () =>
|
const createNodePtyError = () =>
|
||||||
new Error(
|
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
|
// 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
|
// this will inform users in case there are errors in the config instead of instant exit
|
||||||
const runDuration = new Date().getTime() - this.initTimestamp;
|
const runDuration = new Date().getTime() - this.initTimestamp;
|
||||||
if (e.exitCode > 0 && runDuration < 1000) {
|
const fallBackShellConfig = getFallBackShellConfig(shell, shellArgs, defaultShell, defaultShellArgs);
|
||||||
const defaultShellConfig = {shell: defaultShell, shellArgs: defaultShellArgs};
|
if (e.exitCode > 0 && runDuration < 1000 && fallBackShellConfig) {
|
||||||
const msg = `
|
const msg = `
|
||||||
shell exited in ${runDuration} ms with exit code ${e.exitCode}
|
shell exited in ${runDuration} ms with exit code ${e.exitCode}
|
||||||
please check the shell config: ${JSON.stringify({shell, shellArgs}, undefined, 2)}
|
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);
|
console.warn(msg);
|
||||||
this.batcher?.write(msg.replace(/\n/g, '\r\n'));
|
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 {
|
} else {
|
||||||
this.ended = true;
|
this.ended = true;
|
||||||
this.emit('exit');
|
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