Skip to content

Commit

Permalink
feat(js): add EszipError type
Browse files Browse the repository at this point in the history
This commit adds a new error type that is returned from the JS API. It
has fields to describe the location (specifier + line + col) of an
error, in addition to storing the error message.
  • Loading branch information
lucacasonato committed Sep 26, 2022
1 parent c489c01 commit 78ccefa
Show file tree
Hide file tree
Showing 11 changed files with 359 additions and 174 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"deno.enable": true
}
27 changes: 17 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ wasm-bindgen-futures = { version = "0.4.28" }
tokio = { version = "1.16", features = ["io-std", "io-util"] }
console_error_panic_hook = "0.1.7"
anyhow = "1"
serde = { version = "1.0.145", features = ["derive"] }
20 changes: 18 additions & 2 deletions lib/eszip_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { build, Parser } from "./mod.ts";
import { build, EszipError, Parser } from "./mod.ts";
import {
assert,
assertEquals,
} from "https://deno.land/std@0.123.0/testing/asserts.ts";
assertRejects,
} from "https://deno.land/std@0.155.0/testing/asserts.ts";

Deno.test("roundtrip build + parse", async () => {
const eszip = await build([
Expand Down Expand Up @@ -47,3 +48,18 @@ Deno.test("build default loader", async () => {
const eszip = await build(["https://deno.land/std@0.123.0/fs/mod.ts"]);
assert(eszip instanceof Uint8Array);
});

Deno.test("eszip error", async () => {
const err = await assertRejects(
() => build(["file:///does/not/exist.ts"]),
EszipError,
);
assertEquals(
err.specifier,
"file:///does/not/exist.ts",
);
assertEquals(
err.message,
"Module not found.",
);
});
Loading

0 comments on commit 78ccefa

Please sign in to comment.