From ea7b17520ac2521ffc696e00ee9d9e11b671a359 Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Wed, 21 Mar 2018 14:24:48 +0000 Subject: [PATCH] refactor(atom): update error handling --- packages/atom/src/atom.ts | 3 ++- packages/atom/src/cursor.ts | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/atom/src/atom.ts b/packages/atom/src/atom.ts index caf2e25b17..8a8e2cd717 100644 --- a/packages/atom/src/atom.ts +++ b/packages/atom/src/atom.ts @@ -1,4 +1,5 @@ import { IEquiv, Watch, Predicate } from "@thi.ng/api/api"; +import { illegalState } from "@thi.ng/api/error"; import { IWatch } from "@thi.ng/api/mixins/iwatch"; import { Path, setIn, updateIn } from "@thi.ng/paths"; @@ -20,7 +21,7 @@ export class Atom implements constructor(val?: T, valid?: Predicate) { if (valid && !valid(val)) { - throw new Error("initial state did not validate"); + illegalState("initial state value did not validate"); } this.value = val; this.valid = valid; diff --git a/packages/atom/src/cursor.ts b/packages/atom/src/cursor.ts index a65eaa60d6..deb6a2d2b4 100644 --- a/packages/atom/src/cursor.ts +++ b/packages/atom/src/cursor.ts @@ -1,4 +1,5 @@ import { IID, IRelease, Watch } from "@thi.ng/api/api"; +import { illegalArity, illegalArgs } from "@thi.ng/api/error"; import { isArray } from "@thi.ng/checks/is-array"; import { isFunction } from "@thi.ng/checks/is-function"; import { Path, getter, setter } from "@thi.ng/paths"; @@ -65,7 +66,7 @@ export class Cursor implements update = setter(opts.path); } } else { - throw new Error("missing path config"); + illegalArgs("missing path config"); } break; case 2: @@ -77,13 +78,13 @@ export class Cursor implements [parent, lookup, update] = args; break; default: - throw new Error(`illegal arity: ${args.length}`); + illegalArity(args.length); } this.parent = parent; this.id = id || `cursor-${Cursor.NEXT_ID++}`; this.selfUpdate = false; if (!lookup || !update) { - throw new Error("illegal args"); + illegalArgs(); } this.local = new Atom(lookup(parent.deref()), validate); this.local.addWatch(this.id, (_, prev, curr) => {