Skip to content

Commit

Permalink
Give more info in error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
samestep committed Feb 22, 2024
1 parent 83d4e92 commit 7e1a3b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,15 @@ class Autodiff {

const(ref: binaryen.ExpressionRef, info: binaryen.ConstInfo): Result {
if (typeof info.value !== "number")
throw Error("Unsupported constant value");
throw Error(`Unsupported constant kind: ${typeof info.value}`);
switch (info.type) {
case binaryen.f64:
return {
fwd: this.mod.f64.const(info.value),
bwd: this.makeBwd(binaryen.f64),
};
default:
throw Error("Unsupported constant type");
throw Error(`Unsupported constant type: ${info.type}`);
}
}

Expand Down Expand Up @@ -341,7 +341,7 @@ class Autodiff {
return { fwd: this.mod.f64.div(left.fwd, right.fwd), bwd: dz };
}
default:
throw Error("Unsupported binary operation");
throw Error(`Unsupported binary operation: ${info.op}`);
}
}

Expand All @@ -363,7 +363,7 @@ class Autodiff {
case binaryen.BinaryId:
return this.binary(ref, info as binaryen.BinaryInfo);
default:
throw Error("Unsupported expression");
throw Error(`Unsupported expression ID: ${info.id}`);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/tape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ class Taper implements Block {
}

const(ref: binaryen.ExpressionRef, info: binaryen.ConstInfo): Value {
if (typeof info.value !== "number") throw Error("Unsupported constant");
if (typeof info.value !== "number")
throw Error(`Unsupported constant kind: ${typeof info.value}`);
return { kind: ValueKind.Const, value: info.value };
}

Expand Down Expand Up @@ -163,7 +164,7 @@ class Taper implements Block {
case binaryen.BinaryId:
return this.binary(ref, info as binaryen.BinaryInfo);
default:
throw Error("Unsupported expression");
throw Error(`Unsupported expression ID: ${info.id}`);
}
}

Expand Down

0 comments on commit 7e1a3b1

Please sign in to comment.