From cf64111b3ad4714bf1187015951fba9053722492 Mon Sep 17 00:00:00 2001 From: Wu Tingfeng Date: Tue, 30 Sep 2025 11:44:08 +0800 Subject: [PATCH 1/4] fix: catch UnknownJSTypeError for node and chrome platform. --- lib/src/platform_check/web.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/platform_check/web.dart b/lib/src/platform_check/web.dart index 59ef673f..ea362344 100644 --- a/lib/src/platform_check/web.dart +++ b/lib/src/platform_check/web.dart @@ -16,7 +16,8 @@ class PlatformWeb extends Platform { try { Random.secure(); useBuiltInRng = true; - } on UnsupportedError { + } catch (_) { + // throws UnknownJsTypeError. See 'dart:_js_types'. useBuiltInRng = false; } } From c52438328997bffc9cf6b42dcf862e8eb873c611 Mon Sep 17 00:00:00 2001 From: Wu Tingfeng Date: Thu, 2 Oct 2025 10:38:36 +0800 Subject: [PATCH 2/4] fix: Increase timeout for chrome workflow. --- .github/workflows/chrome.workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/chrome.workflow.yml b/.github/workflows/chrome.workflow.yml index 4e5bbafd..d7162520 100644 --- a/.github/workflows/chrome.workflow.yml +++ b/.github/workflows/chrome.workflow.yml @@ -37,4 +37,4 @@ jobs: run: dart pub get - name: Test chrome - run: dart test -j 1 -p chrome + run: dart test --timeout 2x -j 1 -p chrome From a7e2e7e2135b1e1960300be4f81d3519357fac18 Mon Sep 17 00:00:00 2001 From: Wu Tingfeng Date: Thu, 2 Oct 2025 19:05:46 +0800 Subject: [PATCH 3/4] fix: Handle errors more specifically. --- lib/src/platform_check/web.dart | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/src/platform_check/web.dart b/lib/src/platform_check/web.dart index ea362344..2fe3895f 100644 --- a/lib/src/platform_check/web.dart +++ b/lib/src/platform_check/web.dart @@ -13,12 +13,18 @@ class PlatformWeb extends Platform { static bool useBuiltInRng = false; PlatformWeb() { + useBuiltInRng = false; try { Random.secure(); useBuiltInRng = true; - } catch (_) { - // throws UnknownJsTypeError. See 'dart:_js_types'. - useBuiltInRng = false; + } on UnsupportedError { + // Random.secure() normally throws this error if + // no cryptographically secure random number source is available. + } catch (e) { + // For Node.js with dart2js compiler, the following error is expected. + if (e.runtimeType.toString() == 'UnknownJsTypeError') { + // This error is internal to 'dart:_js_helper'. + } } } From 55f04229dc77fc8c771e29c9cb9089af64196380 Mon Sep 17 00:00:00 2001 From: Wu Tingfeng Date: Fri, 3 Oct 2025 06:50:25 +0800 Subject: [PATCH 4/4] fix: rethrow unknown exception. --- lib/src/platform_check/web.dart | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/src/platform_check/web.dart b/lib/src/platform_check/web.dart index 2fe3895f..b23a7382 100644 --- a/lib/src/platform_check/web.dart +++ b/lib/src/platform_check/web.dart @@ -21,9 +21,10 @@ class PlatformWeb extends Platform { // Random.secure() normally throws this error if // no cryptographically secure random number source is available. } catch (e) { - // For Node.js with dart2js compiler, the following error is expected. - if (e.runtimeType.toString() == 'UnknownJsTypeError') { - // This error is internal to 'dart:_js_helper'. + // For Node.js with dart2js compiler, the UnknownJsTypeError error is expected. + // This error is internal to 'dart:_js_helper' so we need to inspect the runtimeType. + if (!(e.runtimeType.toString() == 'UnknownJsTypeError')) { + rethrow; } } } @@ -55,7 +56,8 @@ class _JsBuiltInEntropySource implements EntropySource { @override Uint8List getBytes(int len) { return Uint8List.fromList( - List.generate(len, (i) => _src.nextInt(256))); + List.generate(len, (i) => _src.nextInt(256)), + ); } }