-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fixes #14: Managing errors #16
Open
julienw
wants to merge
1
commit into
fxbox:master
Choose a base branch
from
julienw:14-managing-errors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# What's the problem we're trying to solve ? | ||
|
||
* Display errors to the user in the web application | ||
* Give hints to the user about how to fix these errors | ||
* Only the foxbox should know how to handle errors (example: automatically restart an adapter ?) | ||
|
||
# Concrete issue: starting adapters | ||
|
||
For reference, here is the current code: https://github.com/fxbox/foxbox/blob/998b6e0e1e1fd3cba3b711783eaa7000c2f66a0d/src/adapters/mod.rs#L61-L69 | ||
|
||
Basically we unwrap on any error. Some adapters are not returning an Error for some errors because of this. | ||
|
||
The end-user can't see panics because he only accesses the app through a web browser. | ||
So we need another way to log the error instead and let the user act on it (especially | ||
we might need to be able to restart the foxbox from the browser -- but this is for another issue, I think). | ||
|
||
# Some solutions | ||
|
||
## 1. Error levels | ||
|
||
* init methods return a taxonomied error enum. | ||
* this error would show error levels: eg: Warn, Fatal, Critical. | ||
* this error would contain the cause. The cause should be a real error that implements Display/Debug/Error. | ||
* the box would log the result somewhere the user can look at (but this can be in a separate RFC). For now we could simply log warnings and panic at fatal and critical errors. | ||
|
||
```rust | ||
#[derive(Debug, Clone, Copy)] | ||
enum ErrorLevel { | ||
Warn, | ||
Fatal, | ||
Critical, | ||
} | ||
|
||
#[derive(Debug)] | ||
enum Error { | ||
AdapterStartError { level: ErrorLevel, cause: Error }, | ||
CannotCreateTLSCert { level: ErrorLevel, cause: Error }, | ||
... | ||
} | ||
|
||
use std::error; | ||
impl error::Error for Error { | ||
... | ||
} | ||
``` | ||
|
||
Adapter init methods could return a Taxonomy-defined method that would be automatically converted to a Foxbox' error using a `From<TaxError>` implementation. | ||
|
||
## 2. Custom Logger | ||
|
||
* we replace env_logger with a logger that would keep the logs in a central place to display it through a web browser | ||
* the adapters init function directly uses this to log what needs to be logged | ||
* the adapters init function returns a Error only for Critical errors. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this question. As soon as we have |
||
Q: how to scale to other errors ? |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For the moment, I prefer this idea.