Skip to content

Commit 78ccefa

Browse files
committed
feat(js): add EszipError type
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.
1 parent c489c01 commit 78ccefa

File tree

11 files changed

+359
-174
lines changed

11 files changed

+359
-174
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"deno.enable": true
3+
}

Cargo.lock

Lines changed: 17 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ wasm-bindgen-futures = { version = "0.4.28" }
2121
tokio = { version = "1.16", features = ["io-std", "io-util"] }
2222
console_error_panic_hook = "0.1.7"
2323
anyhow = "1"
24+
serde = { version = "1.0.145", features = ["derive"] }

lib/eszip_test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { build, Parser } from "./mod.ts";
1+
import { build, EszipError, Parser } from "./mod.ts";
22
import {
33
assert,
44
assertEquals,
5-
} from "https://deno.land/std@0.123.0/testing/asserts.ts";
5+
assertRejects,
6+
} from "https://deno.land/std@0.155.0/testing/asserts.ts";
67

78
Deno.test("roundtrip build + parse", async () => {
89
const eszip = await build([
@@ -47,3 +48,18 @@ Deno.test("build default loader", async () => {
4748
const eszip = await build(["https://deno.land/std@0.123.0/fs/mod.ts"]);
4849
assert(eszip instanceof Uint8Array);
4950
});
51+
52+
Deno.test("eszip error", async () => {
53+
const err = await assertRejects(
54+
() => build(["file:///does/not/exist.ts"]),
55+
EszipError,
56+
);
57+
assertEquals(
58+
err.specifier,
59+
"file:///does/not/exist.ts",
60+
);
61+
assertEquals(
62+
err.message,
63+
"Module not found.",
64+
);
65+
});

0 commit comments

Comments
 (0)