marigold-dev / marigold-dev/deku
Principled Exception Handling
- Dominant language
- OCaml
- Stars
- 82
- Forks
- 17
- PR merge metrics
- No merged PRs in 30d
Description
I believe exceptions are a useful paradigm in Deku's context; however, we need to impose some sort of global discipline on how they're used. For example, in #497, we introduced some code
```
if then
exit 1;
```
I believe the behavior (crashing if we can't figure out how to go forward) is correct; but I think it's a bit odd to allow any place in the codebase to crash the node like this.
I think Rust's `panic` macro is good: by default you cannot catch a `panic` because it represents a truly unrecoverable state (there is an API to override this behavior that is used a few special cases like testing frameworks and thread libs, but even then the compiler warns you about this). You can call `panic` from anywhere, but at least there is a single keyword you can `grep` or use linting rules for.
A suggested discipline we could use for exceptions:
- Disallow any functions like `exit` by default via linting.
- Forbid functions that catch everything like `try ... with _ -> ...`
- Have an extensible variant like `type global_exception = ..` that we extend when we need to crash the program. raise an exception of this type whenever we need to.
- have a single place that hanldes these crashes, enforced by linting.
Related: #408
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the behavior introduced in #497 and the related discussion in #408, then search the codebase for exit calls and broad exception handlers. Done means agreeing on and implementing a project-wide exception discipline, including enforcement and a single crash-handling location; the issue does not name files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100