Skip to content

Commit 4c36f76

Browse files
MangelMaximeklofbergclaude
authored
fix(js/ts): make Exception.ToString() return the message instead of "Exception" (#4635)
Co-authored-by: Kristofer Löfberg <kristofer.lofberg@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 14f1db6 commit 4c36f76

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/fable-library-ts/Util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ export class Exception {
8484
constructor(msg?: string) {
8585
this.message = msg ?? "";
8686
}
87+
88+
toString() {
89+
return this.message;
90+
}
8791
}
8892

8993
export function isException(x: any) {

tests/Js/Main/TypeTests.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,15 @@ let tests =
13931393
| ex -> (false, "unknown", 0.)
13941394
|> equal (true, "Code: 5", 5.5)
13951395

1396+
testCase "Exception ToString contains the message" <| fun () -> // See #4197
1397+
let msg =
1398+
try
1399+
failwith "test message"
1400+
""
1401+
with ex -> ex.ToString()
1402+
1403+
msg.Contains("test message") |> equal true
1404+
13961405
testCase "reraise works" <| fun () ->
13971406
try
13981407
try

0 commit comments

Comments
 (0)