Skip to content

Commit

Permalink
Custom panic exception
Browse files Browse the repository at this point in the history
Now that we have a prelude!
  • Loading branch information
dusty-phillips committed Aug 20, 2024
1 parent 5ac853f commit f87dbe1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/generator.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn generate_expression(expression: python.Expression) {
generate_expression(expression) |> string_builder.prepend("not ")
python.Panic(expression) ->
generate_expression(expression)
|> string_builder.prepend("raise BaseException(")
|> string_builder.prepend("raise GleamPanic(")
|> string_builder.append(")")
python.Todo(expression) ->
generate_expression(expression)
Expand Down
3 changes: 3 additions & 0 deletions src/python_prelude.gleam
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pub const gleam_builtins = "
import dataclasses
class GleamPanic(BaseException):
pass
"

pub const prelude = "from gleam_builtins import *\n\n"
4 changes: 2 additions & 2 deletions test/expression_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn empty_panic_test() {
"from gleam_builtins import *
def main():
raise BaseException(\"panic expression evaluated\")
raise GleamPanic(\"panic expression evaluated\")
",
)
}
Expand All @@ -161,7 +161,7 @@ pub fn string_panic_test() {
"from gleam_builtins import *
def main():
raise BaseException(\"my custom panic\")
raise GleamPanic(\"my custom panic\")
",
)
}
Expand Down

0 comments on commit f87dbe1

Please sign in to comment.