diff --git a/src/common.ts b/src/common.ts index 9de0f34..9a6db1d 100644 --- a/src/common.ts +++ b/src/common.ts @@ -5,6 +5,7 @@ const exec = util.promisify(child_process.exec); import { Config } from './config'; import {OptionValues} from 'commander'; import {getOptions} from './utils'; +import {MultiClaspErrors} from './mutli-clasp-errors'; /** @@ -69,6 +70,8 @@ export async function foreachClasp(fn:(claspConfig:SingleClasp)=>Promise): */ export async function genericAction(): Promise { foreachClasp(async (claspConfig)=>{ - await runClasp(claspConfig, process.argv[2], getOptions()); + if(!(await runClasp(claspConfig, process.argv[2], getOptions()))){ + throw MultiClaspErrors.ClaspError; + } }); } diff --git a/src/mutli-clasp-errors.ts b/src/mutli-clasp-errors.ts new file mode 100644 index 0000000..3c121ea --- /dev/null +++ b/src/mutli-clasp-errors.ts @@ -0,0 +1,7 @@ +/** + * Multi Clasp Errors. + */ +export enum MultiClaspErrors { + InvalidJson = "Invalid json", + ClaspError = "Clasp Error", +} diff --git a/src/Globals.d.ts b/src/types.d.ts similarity index 99% rename from src/Globals.d.ts rename to src/types.d.ts index 34e73cf..74dbd38 100644 --- a/src/Globals.d.ts +++ b/src/types.d.ts @@ -1,4 +1,3 @@ - /** * SingleClasp configuration type */ diff --git a/src/utils.ts b/src/utils.ts index 57906ae..aab4547 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,5 @@ +import {MultiClaspErrors} from "./mutli-clasp-errors"; + /** * Parses input string into a valid JSON object or throws a `ClaspError` error. * @param value JSON string. @@ -6,7 +8,7 @@ export const parseJsonOrDie = (value: string): T => { try { return JSON.parse(value) as T; } catch { - throw "Invalid json"; + throw MultiClaspErrors.InvalidJson; } }; diff --git a/test/run.test.ts b/test/run.test.ts index 9ac58f8..6a72f7c 100644 --- a/test/run.test.ts +++ b/test/run.test.ts @@ -1,9 +1,10 @@ +import {MultiClaspErrors} from "../src/mutli-clasp-errors"; import {getRunClaspArgs} from "../src/run"; describe('run.ts tests', ()=>{ test('wrong inputs', () => { - expect(()=>(getRunClaspArgs("", {nondev:false, params:''}))).toThrow("Invalid json"); + expect(()=>(getRunClaspArgs("", {nondev:false, params:''}))).toThrow(MultiClaspErrors.InvalidJson); }); test('good inputs', () => { expect(getRunClaspArgs("testFunc", {nondev:false, params:'[]'})).toBe("testFunc --params '[]'");