Skip to content

Commit

Permalink
Moved errors to MultiClaspErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
fantonangeli committed Nov 13, 2021
1 parent 0a75052 commit bc04826
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


/**
Expand Down Expand Up @@ -69,6 +70,8 @@ export async function foreachClasp(fn:(claspConfig:SingleClasp)=>Promise<void>):
*/
export async function genericAction(): Promise<void> {
foreachClasp(async (claspConfig)=>{
await runClasp(claspConfig, process.argv[2], getOptions());
if(!(await runClasp(claspConfig, process.argv[2], getOptions()))){
throw MultiClaspErrors.ClaspError;
}
});
}
7 changes: 7 additions & 0 deletions src/mutli-clasp-errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Multi Clasp Errors.
*/
export enum MultiClaspErrors {
InvalidJson = "Invalid json",
ClaspError = "Clasp Error",
}
1 change: 0 additions & 1 deletion src/Globals.d.ts → src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* SingleClasp configuration type
*/
Expand Down
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -6,7 +8,7 @@ export const parseJsonOrDie = <T>(value: string): T => {
try {
return JSON.parse(value) as T;
} catch {
throw "Invalid json";
throw MultiClaspErrors.InvalidJson;
}
};

Expand Down
3 changes: 2 additions & 1 deletion test/run.test.ts
Original file line number Diff line number Diff line change
@@ -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 '[]'");
Expand Down

0 comments on commit bc04826

Please sign in to comment.