Skip to content

Commit a6ec0f7

Browse files
Custom panic exception
Now that we have a prelude!
1 parent 5ac853f commit a6ec0f7

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ PRs are welcome.
4747

4848
### TODO
4949

50-
- panic should probably raise a custom/stdlib exception instead of BaseException
5150
- custom types with unlabelled fields are not working
5251
- Given that labelled and unlabelled fields can be mixed on one class, I have a feeling we have to ditch dataclasses. Probably a custom class with slots, a dict of names to indices, and a custom **match_args** that can handle tuple-like _or_ record-like syntax?
5352
- some complex expressions aren't implemented yet

src/generator.gleam

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn generate_expression(expression: python.Expression) {
7676
generate_expression(expression) |> string_builder.prepend("not ")
7777
python.Panic(expression) ->
7878
generate_expression(expression)
79-
|> string_builder.prepend("raise BaseException(")
79+
|> string_builder.prepend("raise GleamPanic(")
8080
|> string_builder.append(")")
8181
python.Todo(expression) ->
8282
generate_expression(expression)

src/python_prelude.gleam

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
pub const gleam_builtins = "
22
import dataclasses
3+
4+
class GleamPanic(BaseException):
5+
pass
36
"
47

58
pub const prelude = "from gleam_builtins import *\n\n"

test/expression_test.gleam

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn empty_panic_test() {
146146
"from gleam_builtins import *
147147
148148
def main():
149-
raise BaseException(\"panic expression evaluated\")
149+
raise GleamPanic(\"panic expression evaluated\")
150150
",
151151
)
152152
}
@@ -161,7 +161,7 @@ pub fn string_panic_test() {
161161
"from gleam_builtins import *
162162
163163
def main():
164-
raise BaseException(\"my custom panic\")
164+
raise GleamPanic(\"my custom panic\")
165165
",
166166
)
167167
}

0 commit comments

Comments
 (0)