From 6fd1a4203a3ec5d811d4dd8cf18cc5a71c68eb56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristofer=20L=C3=B6fberg?= Date: Mon, 8 Jun 2026 22:26:17 +0200 Subject: [PATCH 1/2] fix(js): make Exception.ToString() return the message instead of "Exception" Since #4197 System.Exception compiles to Fable's own Exception class rather than native Error. That class had no toString(), so ex.ToString() fell back to the constructor name ("Exception") instead of the message. Add a toString() returning the message, matching the Dart and Python targets. Co-Authored-By: Claude Opus 4.8 --- src/fable-library-ts/Util.ts | 4 ++++ tests/Js/Main/TypeTests.fs | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/fable-library-ts/Util.ts b/src/fable-library-ts/Util.ts index 2435c08bff..2ced013e02 100644 --- a/src/fable-library-ts/Util.ts +++ b/src/fable-library-ts/Util.ts @@ -84,6 +84,10 @@ export class Exception { constructor(msg?: string) { this.message = msg ?? ""; } + + toString() { + return this.message; + } } export function isException(x: any) { diff --git a/tests/Js/Main/TypeTests.fs b/tests/Js/Main/TypeTests.fs index 4bbb013759..49d719099f 100644 --- a/tests/Js/Main/TypeTests.fs +++ b/tests/Js/Main/TypeTests.fs @@ -1393,6 +1393,15 @@ let tests = | ex -> (false, "unknown", 0.) |> equal (true, "Code: 5", 5.5) + testCase "Exception ToString contains the message" <| fun () -> // See #4197 + let msg = + try + failwith "test message" + "" + with ex -> ex.ToString() + // .NET returns "System.Exception: test message", Fable returns just the message + msg.Contains("test message") |> equal true + testCase "reraise works" <| fun () -> try try From 97edce06f89aaa605b67ab2e9fff7a9647f27a20 Mon Sep 17 00:00:00 2001 From: Mangel Maxime Date: Tue, 9 Jun 2026 11:24:16 +0200 Subject: [PATCH 2/2] chore: remove comment --- tests/Js/Main/TypeTests.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Js/Main/TypeTests.fs b/tests/Js/Main/TypeTests.fs index 49d719099f..0377816ead 100644 --- a/tests/Js/Main/TypeTests.fs +++ b/tests/Js/Main/TypeTests.fs @@ -1399,7 +1399,7 @@ let tests = failwith "test message" "" with ex -> ex.ToString() - // .NET returns "System.Exception: test message", Fable returns just the message + msg.Contains("test message") |> equal true testCase "reraise works" <| fun () ->