From 04a9cc95ac1349ab192c93c231c1ac97ee02fb00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 9 Sep 2024 21:51:55 +0100 Subject: feat: Add better error messages for unstable APIs (#25519) This commit improves error messages for unstable APIs: - `--unstable-broadcast-channel` - `--unstable-cron` - `--unstable-http` - `--unstable-kv` - `--unstable-temporal` By providing information and hints what went wrong and how the error can be fixed. It reuses the same infra that was added in https://github.com/denoland/deno/pull/21764. --- tests/specs/run/unstable/__test__.jsonc | 34 ++++++++++++++++++++++++++ tests/specs/run/unstable/broadcast_channel.out | 7 ++++++ tests/specs/run/unstable/broadcast_channel.ts | 1 + tests/specs/run/unstable/cron.out | 7 ++++++ tests/specs/run/unstable/cron.ts | 1 + tests/specs/run/unstable/http.out | 7 ++++++ tests/specs/run/unstable/http.ts | 1 + tests/specs/run/unstable/http_wss.out | 7 ++++++ tests/specs/run/unstable/http_wss.ts | 1 + tests/specs/run/unstable/kv.out | 7 ++++++ tests/specs/run/unstable/kv.ts | 1 + tests/specs/run/unstable/temporal.out | 7 ++++++ tests/specs/run/unstable/temporal.ts | 1 + 13 files changed, 82 insertions(+) create mode 100644 tests/specs/run/unstable/__test__.jsonc create mode 100644 tests/specs/run/unstable/broadcast_channel.out create mode 100644 tests/specs/run/unstable/broadcast_channel.ts create mode 100644 tests/specs/run/unstable/cron.out create mode 100644 tests/specs/run/unstable/cron.ts create mode 100644 tests/specs/run/unstable/http.out create mode 100644 tests/specs/run/unstable/http.ts create mode 100644 tests/specs/run/unstable/http_wss.out create mode 100644 tests/specs/run/unstable/http_wss.ts create mode 100644 tests/specs/run/unstable/kv.out create mode 100644 tests/specs/run/unstable/kv.ts create mode 100644 tests/specs/run/unstable/temporal.out create mode 100644 tests/specs/run/unstable/temporal.ts (limited to 'tests/specs') diff --git a/tests/specs/run/unstable/__test__.jsonc b/tests/specs/run/unstable/__test__.jsonc new file mode 100644 index 000000000..5748c5461 --- /dev/null +++ b/tests/specs/run/unstable/__test__.jsonc @@ -0,0 +1,34 @@ +{ + "tests": { + "broadcast_channel": { + "args": "run broadcast_channel.ts", + "exitCode": 1, + "output": "broadcast_channel.out" + }, + "cron": { + "args": "run cron.ts", + "exitCode": 1, + "output": "cron.out" + }, + "http": { + "args": "run http.ts", + "exitCode": 1, + "output": "http.out" + }, + "http_wss": { + "args": "run http_wss.ts", + "exitCode": 1, + "output": "http_wss.out" + }, + "kv": { + "args": "run kv.ts", + "exitCode": 1, + "output": "kv.out" + }, + "temporal": { + "args": "run temporal.ts", + "exitCode": 1, + "output": "temporal.out" + } + } +} diff --git a/tests/specs/run/unstable/broadcast_channel.out b/tests/specs/run/unstable/broadcast_channel.out new file mode 100644 index 000000000..8a9a09ef2 --- /dev/null +++ b/tests/specs/run/unstable/broadcast_channel.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: BroadcastChannel is not defined +new BroadcastChannel("hello"); +^ + at [WILDCARD]broadcast_channel.ts:1:1 + + info: BroadcastChannel is an unstable API. + hint: Run again with `--unstable-broadcast-channel` flag to enable this API. diff --git a/tests/specs/run/unstable/broadcast_channel.ts b/tests/specs/run/unstable/broadcast_channel.ts new file mode 100644 index 000000000..5fcbc34b5 --- /dev/null +++ b/tests/specs/run/unstable/broadcast_channel.ts @@ -0,0 +1 @@ +new BroadcastChannel("hello"); diff --git a/tests/specs/run/unstable/cron.out b/tests/specs/run/unstable/cron.out new file mode 100644 index 000000000..76558bb38 --- /dev/null +++ b/tests/specs/run/unstable/cron.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) TypeError: Deno.cron is not a function +Deno.cron(); + ^ + at [WILDCARD]cron.ts:1:6 + + info: Deno.cron() is an unstable API. + hint: Run again with `--unstable-cron` flag to enable this API. diff --git a/tests/specs/run/unstable/cron.ts b/tests/specs/run/unstable/cron.ts new file mode 100644 index 000000000..8ec4f21ea --- /dev/null +++ b/tests/specs/run/unstable/cron.ts @@ -0,0 +1 @@ +Deno.cron(); diff --git a/tests/specs/run/unstable/http.out b/tests/specs/run/unstable/http.out new file mode 100644 index 000000000..55e143c25 --- /dev/null +++ b/tests/specs/run/unstable/http.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) TypeError: Deno.createHttpClient is not a function +Deno.createHttpClient(); + ^ + at [WILDCARD]http.ts:1:6 + + info: Deno.createHttpClient() is an unstable API. + hint: Run again with `--unstable-http` flag to enable this API. diff --git a/tests/specs/run/unstable/http.ts b/tests/specs/run/unstable/http.ts new file mode 100644 index 000000000..568d6a7cc --- /dev/null +++ b/tests/specs/run/unstable/http.ts @@ -0,0 +1 @@ +Deno.createHttpClient(); diff --git a/tests/specs/run/unstable/http_wss.out b/tests/specs/run/unstable/http_wss.out new file mode 100644 index 000000000..f62deaee8 --- /dev/null +++ b/tests/specs/run/unstable/http_wss.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: WebSocketStream is not defined +const wss = new WebSocketStream("ws://127.0.0.1:4513"); + ^ + at [WILDCARD]http_wss.ts:1:13 + + info: new WebSocketStream() is an unstable API. + hint: Run again with `--unstable-net` flag to enable this API. diff --git a/tests/specs/run/unstable/http_wss.ts b/tests/specs/run/unstable/http_wss.ts new file mode 100644 index 000000000..f4885f20f --- /dev/null +++ b/tests/specs/run/unstable/http_wss.ts @@ -0,0 +1 @@ +const wss = new WebSocketStream("ws://127.0.0.1:4513"); diff --git a/tests/specs/run/unstable/kv.out b/tests/specs/run/unstable/kv.out new file mode 100644 index 000000000..d0916604c --- /dev/null +++ b/tests/specs/run/unstable/kv.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) TypeError: Deno.openKv is not a function +const db = await Deno.openKv(); + ^ + at [WILDCARD]kv.ts:1:23 + + info: Deno.openKv() is an unstable API. + hint: Run again with `--unstable-kv` flag to enable this API. diff --git a/tests/specs/run/unstable/kv.ts b/tests/specs/run/unstable/kv.ts new file mode 100644 index 000000000..591bc3e37 --- /dev/null +++ b/tests/specs/run/unstable/kv.ts @@ -0,0 +1 @@ +const db = await Deno.openKv(); diff --git a/tests/specs/run/unstable/temporal.out b/tests/specs/run/unstable/temporal.out new file mode 100644 index 000000000..f29f9acf8 --- /dev/null +++ b/tests/specs/run/unstable/temporal.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: Temporal is not defined +Temporal.Now.instant(); +^ + at [WILDCARD]temporal.ts:1:1 + + info: Temporal is an unstable API. + hint: Run again with `--unstable-temporal` flag to enable this API. diff --git a/tests/specs/run/unstable/temporal.ts b/tests/specs/run/unstable/temporal.ts new file mode 100644 index 000000000..92aed7931 --- /dev/null +++ b/tests/specs/run/unstable/temporal.ts @@ -0,0 +1 @@ +Temporal.Now.instant(); -- cgit v1.2.3