Skip to content

Commit

Permalink
refactor(dcons): update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 21, 2018
1 parent 5087ffe commit a046b28
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/dcons/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as api from "@thi.ng/api/api";
import { illegalArgs, illegalState } from "@thi.ng/api/error";
import { compare } from "@thi.ng/api/compare";
import { equiv } from "@thi.ng/api/equiv";
import { isArrayLike } from "@thi.ng/checks/is-arraylike";
Expand Down Expand Up @@ -124,7 +125,7 @@ export class DCons<T> implements

public insertBefore(cell: ConsCell<T>, value: T): DCons<T> {
if (!cell) {
throw new Error("cell is undefined");
illegalArgs("cell is undefined");
}
const newCell = <ConsCell<T>>{ value, next: cell, prev: cell.prev };
if (cell.prev) {
Expand All @@ -139,7 +140,7 @@ export class DCons<T> implements

public insertAfter(cell: ConsCell<T>, value: T): DCons<T> {
if (!cell) {
throw new Error("cell is undefined");
illegalArgs("cell is undefined");
}
const newCell = <ConsCell<T>>{ value, next: cell.next, prev: cell };
if (cell.next) {
Expand Down Expand Up @@ -224,7 +225,7 @@ export class DCons<T> implements
let a = from < 0 ? from + this._length : from;
let b = to < 0 ? to + this._length : to;
if (a < 0 || b < 0) {
throw new Error("invalid indices: ${from} / ${to}")
illegalArgs("invalid indices: ${from} / ${to}")
}
const res = new DCons<T>();
let cell = this.nthCell(a);
Expand Down Expand Up @@ -316,7 +317,7 @@ export class DCons<T> implements
}
this._length--;
} else {
throw new Error("can't pop, empty");
illegalState("can't pop, empty");
}
return this;
}
Expand Down Expand Up @@ -348,7 +349,7 @@ export class DCons<T> implements
public setNth(n: number, v: T) {
const cell = this.nthCell(n);
if (!cell) {
throw new Error(`index out of bounds: ${n}`);
illegalArgs(`index out of bounds: ${n}`);
}
cell.value = v;
return this;
Expand Down

0 comments on commit a046b28

Please sign in to comment.