feat: much better error handling

pull/413/head
Webber 2022-08-31 22:20:38 +02:00
parent 44eb07aa31
commit d915ae20f1
5 changed files with 53 additions and 1707 deletions

View File

@ -25,7 +25,7 @@
"lineWidth": 120, "lineWidth": 120,
"indentWidth": 2, "indentWidth": 2,
"singleQuote": true, "singleQuote": true,
"proseWrap": "preserve" "proseWrap": "always"
} }
} }
} }

View File

@ -24,25 +24,7 @@
"test-i-aws": "cross-env cloudRunnerTests=true cloudRunnerCluster=aws yarn test -i -t \"cloud runner\"", "test-i-aws": "cross-env cloudRunnerTests=true cloudRunnerCluster=aws yarn test -i -t \"cloud runner\"",
"test-i-k8s": "cross-env cloudRunnerTests=true cloudRunnerCluster=k8s yarn test -i -t \"cloud runner\"" "test-i-k8s": "cross-env cloudRunnerTests=true cloudRunnerCluster=k8s yarn test -i -t \"cloud runner\""
}, },
"dependencies": { "dependencies": {},
"@actions/core": "^1.9.1",
"@actions/exec": "^1.1.0",
"@actions/github": "^5.0.0",
"@kubernetes/client-node": "^0.16.3",
"@octokit/core": "^3.5.1",
"async-wait-until": "^2.0.12",
"aws-sdk": "^2.1081.0",
"base-64": "^1.0.0",
"commander": "^9.0.0",
"commander-ts": "^0.2.0",
"kubernetes-client": "^9.0.0",
"nanoid": "^3.3.1",
"reflect-metadata": "^0.1.13",
"semver": "^7.3.5",
"unity-changeset": "^1.6.0",
"uuid": "^8.3.2",
"yaml": "^1.10.2"
},
"devDependencies": { "devDependencies": {
"@arkweid/lefthook": "^0.7.7", "@arkweid/lefthook": "^0.7.7",
"@types/jest": "^28.1.6", "@types/jest": "^28.1.6",

View File

@ -1,5 +1,4 @@
import { yargs, YargsInstance, YargsArguments } from './dependencies.ts'; import { yargs, YargsInstance, YargsArguments, getHomeDir } from './dependencies.ts';
import { default as getHomeDir } from 'https://deno.land/x/dir@1.5.1/home_dir/mod.ts';
import { engineDetection } from './middleware/engine-detection/index.ts'; import { engineDetection } from './middleware/engine-detection/index.ts';
import { CommandInterface } from './command/command-interface.ts'; import { CommandInterface } from './command/command-interface.ts';
import { configureLogger } from './middleware/logger-verbosity/index.ts'; import { configureLogger } from './middleware/logger-verbosity/index.ts';
@ -99,11 +98,13 @@ export class Cli {
private globalOptions() { private globalOptions() {
this.yargs this.yargs
.help('help') .fail(Cli.handleFailure)
.showHelpOnFail(false, 'Specify --help for available options') .help(false) // Fixes broken `_handle` in yargs 17.0.0
.version(false) // Fixes broken `_handle` in yargs 17.0.0
.showHelpOnFail(false) // Fixes broken `_handle` in yargs 17.0.0
.epilogue('for more information, find our manual at https://game.ci/docs/cli') .epilogue('for more information, find our manual at https://game.ci/docs/cli')
.middleware([]) .middleware([])
.exitProcess(true) // prevents `_handle` from being lost .exitProcess(true) // Fixes broken `_handle` in yargs 17.0.0
.strict(true); .strict(true);
} }
@ -119,22 +120,30 @@ export class Cli {
.coerce('projectPath', async (arg) => { .coerce('projectPath', async (arg) => {
return arg.replace(/^~/, getHomeDir()).replace(/\/$/, ''); return arg.replace(/^~/, getHomeDir()).replace(/\/$/, '');
}) })
.middleware([engineDetection, vcsDetection]) .default('engine', '')
.default('engineVersion', '')
.middleware([engineDetection], true)
.default('branch', '')
.middleware([vcsDetection], true)
// Todo - remove these lines with release 3.0.0 // Todo - remove these lines with release 3.0.0
.option('unityVersion', { .option('unityVersion', {
describe: 'Override the engine version to be used', describe: 'Override the engine version to be used',
type: 'string', type: 'string',
default: '',
}) })
.deprecateOption('unityVersion', 'This parameter will be removed. Use engineVersion instead') .deprecateOption('unityVersion', 'This parameter will be removed. Use engineVersion instead')
.middleware([ .middleware(
async (args) => { [
if (!args.unityVersion || args.unityVersion === 'auto' || args.engine !== Engine.unity) return; async (args) => {
if (!args.unityVersion || args.unityVersion === 'auto' || args.engine !== Engine.unity) return;
args.engineVersion = args.unityVersion; args.engineVersion = args.unityVersion;
args.unityVersion = undefined; args.unityVersion = undefined;
}, },
]) ],
true,
)
// End todo // End todo
.middleware([async (args) => this.registerCommand(args, yargs)]); .middleware([async (args) => this.registerCommand(args, yargs)]);
@ -154,4 +163,11 @@ export class Cli {
this.options = options; this.options = options;
} }
private static handleFailure(message: string, error: Error, yargs: YargsInstance) {
if (error) throw error;
log.warning(message);
Deno.exit(1);
}
} }

View File

@ -7,7 +7,7 @@ class GameCI {
const success = await command.execute(options); const success = await command.execute(options);
if (!success) throw new Error(`${command.name} failed.`); if (!success) log.warning(`${command.constructor.name} failed.`);
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(error); console.error(error);

1694
yarn.lock

File diff suppressed because it is too large Load Diff