Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreachable exception? #2001

Open
plajjan opened this issue Nov 25, 2024 · 2 comments
Open

Unreachable exception? #2001

plajjan opened this issue Nov 25, 2024 · 2 comments

Comments

@plajjan
Copy link
Contributor

plajjan commented Nov 25, 2024

I'm writing a bunch of code that is essentially unreachable, or at least should be unreachable and I wonder if it would be helpful to have an exception that more clearly reflects this use. In Zig there is a unreachable that can be used to this exact effect.

raise ValueError() feels like "there was something wrong with the value", but saying raise Unreachable() is more like "there was something wrong with the value and that should never happen because some other part of our program should ensure this value is always valid". See the difference?

wdyt @nordlander ?

@nordlander
Copy link
Contributor

Sounds reasonable. And it's easy to extend the Exception hierarchy, just inherit class Exception. So I guess the only issue is whether the new class should be in builtin. Which sounds reasonable too, I think.

@plajjan
Copy link
Contributor Author

plajjan commented Nov 26, 2024

This is effectively a way for the developer that raises the exception to indicate some intent behind it, like this code should really never be hit. It is indicative of a bug, and not just some slightly wrong input parsing somewhere. But what do we do about it? Zig's unreachable will immediately exit the program. For development builds, I quite like that approach.

Its placement in the exception hierarchy and if we have built-in treatment of it is perhaps what would really set it apart.

Python programmers quite casually do try / except. I don't really want to encourage that in Acton, but it is the simplest code to write. I feel that the semantics of an Unreachable should be that it is not just catcheable, again, at least for dev builds. Since we have an aspiration for always-on systems in prod, I'm not sure what should happen there.

A somewhat similar topic is how out-of-memory exceptions. With a distributed RTS we could automatically retry such failures by migrating an actor to another node. It is similar in that it is challenging to place the exception properly in the hierarchy and potentially have some automatic RTS remedy in some cases but not in others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants