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

test: handle invalid mdx with Result rather than panic #26

Closed
wants to merge 2 commits into from

Conversation

ChristianMurphy
Copy link
Collaborator

unreachable!("out of bounds")

This case goes to unreachable!
https://doc.rust-lang.org/std/macro.unreachable.html

This will always panic! because unreachable! is just a shorthand for panic! with a fixed, specific message.

which means Result is unable to recover.

@wooorm
Copy link
Owner

wooorm commented Oct 29, 2022

This isn’t about the panic, which should be a result btw. It’s just that this unreachable should never be reached. Sort of like an assertion. And it is reached, which should be fixed somehow!

@ChristianMurphy
Copy link
Collaborator Author

This isn’t about the panic, which should be a result

Meaning that it should not panic! or Err?
Or that panic! should automatically convert to Err?
Regarding the later. Rust has two types of exception handling.

Rust groups errors into two major categories: recoverable and unrecoverable errors. For a recoverable error, such as a file not found error, we most likely just want to report the problem to the user and retry the operation. Unrecoverable errors are always symptoms of bugs, like trying to access a location beyond the end of an array, and so we want to immediately stop the program.

Most languages don’t distinguish between these two kinds of errors and handle both in the same way, using mechanisms such as exceptions. Rust doesn’t have exceptions. Instead, it has the type Result<T, E> for recoverable errors and the panic! macro that stops execution when the program encounters an unrecoverable error.

https://doc.rust-lang.org/book/ch09-00-error-handling.html

wooorm pushed a commit that referenced this pull request Apr 22, 2023
@ChristianMurphy
Copy link
Collaborator Author

closed by #60

@ChristianMurphy ChristianMurphy deleted the test/mdx-handle-invalid branch August 15, 2023 18:44
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

Successfully merging this pull request may close these issues.

2 participants