-
Notifications
You must be signed in to change notification settings - Fork 543
react: return domain-specific errors #464
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
Conversation
exercises/react/src/lib.rs
Outdated
@@ -11,6 +11,12 @@ pub enum SetValueError { | |||
ComputeCell, | |||
} | |||
|
|||
#[derive(Debug, PartialEq)] | |||
pub enum RemoveCallbackError { | |||
NonexistentCell, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: It apparently is the case that we never test the NonexistentCell
case. That can be dealt with later.
// Check all dependencies' validity before modifying any of them, | ||
// so that we don't perform an incorrect partial write. | ||
if !dependencies.iter().all(|&id| id < self.cells.len()) { | ||
return Err("Nonexistent input"); | ||
if let Some(&invalid) = dependencies.iter().find(|&dep| *dep >= self.cells.len()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is in fact not a specific reason I wrote find(|&dep| *dep >= self.cells.len())
as opposed to one of these two alternatives:
find(|&&dep| dep >= self.cells.len())
find(|dep| **dep >= self.cells.len())
I really don't know what I'm doing and which is better, so I need help on that.
Last reviewed: ff451ea |
Instead of encouraging `()` as an Err type, we'd prefer to encourage informative errors. In this case, there is only one failure mode (so we do not need a separate error type) but there is a parameter (exactly which cell is invalid) so we'll keep Result to designate the invalid cell. As discussed in #444 A subtask of #462
Now that it's simplified to use Option, we can simply map into the `get_mut`.
This merge was more involved. I'll ask for a re-review on this one to make sure I didn't screw anything up. |
This merge was more involved. I'll ask for a re-review on this one to make sure I didn't screw anything up.
exercises/react/tests/react.rs
Outdated
@@ -206,10 +206,10 @@ fn removing_a_callback_multiple_times_doesnt_interfere_with_other_callbacks() { | |||
let output = reactor.create_compute(&[input], |v| v[0] + 1).unwrap(); | |||
let callback = reactor.add_callback(output, |v| cb1.callback_called(v)).unwrap(); | |||
assert!(reactor.add_callback(output, |v| cb2.callback_called(v)).is_some()); | |||
// We want the first remove to be Ok, but we don't care about the others. | |||
// We want the first remove to be Ok, but the others should be errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still looks correct to me.
Thanks for that! |
Closes #462.
Details are in individual commit messages.
I have no particular preference on whether the five commits comprising this PR should be squashed.