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

Use a consistent pattern for error handling #67

Closed
iffyio opened this issue Jul 7, 2020 · 7 comments · Fixed by #136
Closed

Use a consistent pattern for error handling #67

iffyio opened this issue Jul 7, 2020 · 7 comments · Fixed by #136
Labels
good first issue Good for newcomers kind/cleanup Refactoring code, fixing up documentation, etc

Comments

@iffyio
Copy link
Collaborator

iffyio commented Jul 7, 2020

Currently we use mixtures of tokio::Result and std::result::Result<_, std::io::Error> etc when returning errors which isn't ideal.
We want to pick a single way to handle errors in the codebase by e.g leveraging an existing library, handcrafting structs ourselves etc.

@iffyio iffyio added good first issue Good for newcomers kind/cleanup Refactoring code, fixing up documentation, etc labels Jul 7, 2020
@markmandel
Copy link
Member

Given that we're also planning on allowing people to use this as a library - it seems like we should have our own Error enum(s), and expose those as public, rather than expose the underlying libraries to the outside world (especially if we ever want those to change).

(To be honest, I only recently started to look more at error handling, and getting more of a handle on it)

I'd be inclined to handcraft our of own enums/structs to start, and if we get more complicated, bring in a more sophisticated library as needed. WDYT?

markmandel added a commit that referenced this issue Jul 8, 2020
We needed validation that endpoint names are unique, so implemented a
validation function for config. This had a few ripple on effects:

- impl block for Config, so made sense to pull `from_reader` into that
as a static method.
- Needed concrete Error types (impacts #67) for validation and other
potential error conditions.

`from_reader` will now call validate() to ensure that the struct is
valid before completing.

`validate` was also left as public, since Config's can be manually
created before passing them into `Server.run()`
@iffyio
Copy link
Collaborator Author

iffyio commented Jul 8, 2020

+1 on writing our own structs, it makes sense to introduce a library if/when we know it adds significant value.

markmandel added a commit that referenced this issue Jul 10, 2020
* Add Validation to Config

We needed validation that endpoint names are unique, so implemented a
validation function for config. This had a few ripple on effects:

- impl block for Config, so made sense to pull `from_reader` into that
as a static method.
- Needed concrete Error types (impacts #67) for validation and other
potential error conditions.

`from_reader` will now call validate() to ensure that the struct is
valid before completing.

`validate` was also left as public, since Config's can be manually
created before passing them into `Server.run()`
@markmandel
Copy link
Member

I feel like we've resolved this for now - what do you think, can we close this?

@iffyio
Copy link
Collaborator Author

iffyio commented Aug 4, 2020

We currently have some places where we needed to return proper errors, e.g in server.rs we still pass tokio result - the idea was to resolve those cases in this ticket.

@markmandel
Copy link
Member

We currently have some places where we needed to return proper errors, e.g in server.rs we still pass tokio result - the idea was to resolve those cases in this ticket.

Ah yes! I had forgotten! Excellent point.

@markmandel
Copy link
Member

Just did a quick review of server.rs and session.rs -- I think we are good to close this now.

One thing I did note - we probably should create a ticket to review of public methods, and restrict them to only being available to the crate or smaller.

Because we do still expose tokio::io::Result from some public methods, which is fine if they are only used internally (and restricted as such), but not if they are used as a public library api surface.

How does that sound?

@iffyio
Copy link
Collaborator Author

iffyio commented Nov 14, 2020

I can create a PR to replace the tokio::io::Result usages and link that to close this PR :+1:

iffyio added a commit that referenced this issue Nov 14, 2020
markmandel added a commit that referenced this issue Nov 17, 2020
* Remove remaining returns of Tokio Result

Fixes #67

* Use errors file and rename InternalError

Co-authored-by: Mark Mandel <markmandel@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers kind/cleanup Refactoring code, fixing up documentation, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants