Skip to content

How to propagte an error from update function #963

Answered by yusdacra
d-mceneaney asked this question in Q&A
Discussion options

You must be logged in to vote

You can't return a result from the update function, but what you can do is store the error as part of your application state. So something like:

struct App {
	last_result: Result<(), Error>,
}

impl Sandbox for App {
	fn update(&mut self, message: Message) {
		match message {
			Message::Something => {
				let result = do_something();
				if result.is_err() {
					self.last_result = result;
				}
			}
		}
	}
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@d-mceneaney
Comment options

Answer selected by d-mceneaney
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants