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

Custom errors #576

Closed
kim opened this issue Jun 24, 2020 · 3 comments
Closed

Custom errors #576

kim opened this issue Jun 24, 2020 · 3 comments

Comments

@kim
Copy link
Contributor

kim commented Jun 24, 2020

When developing custom transports, I found it a bit unsatisfying that the only way to construct a custom git2::Error is via Error::from_str -- as the code and class are very generic, it essentially always bubbles up as an "unknown error". I think this means that transport::subtransport_action should also call libgit2_sys::git_error_set_str, but if that would be the case, it would still be nice to also be able to tweak the code and class (eg. by making Error::from_raw public).

Would you be willing to accept a patch which does these two things?

@alexcrichton
Copy link
Member

I don't think I'd want to stabilize from_raw literally as-is, but providing more constructors and/or modifiers makes sense to me!

kim added a commit to kim/git2-rs that referenced this issue Jun 24, 2020
…ust-lang#576)

Previously, the propagated error would always be the default "unknown error" as
returned by `Error::last_error` if `git_error_last` returns a null pointer. The
attached test case is rather trivial, but can be used to reproduce the old and
new behaviour.
kim added a commit to kim/git2-rs that referenced this issue Jun 24, 2020
Previously, the propagated error from a custom transport would always be the
default "unknown error" as returned by `Error::last_error` if `git_error_last`
returns a null pointer. The attached test case is rather trivial, but can be
used to reproduce the old and new behaviour.
@kim
Copy link
Contributor Author

kim commented Jun 24, 2020

That makes sense, although I'm unsure where to draw the line. I've submitted a PR for the first part, and will ponder on the second for a bit.

kim added a commit to kim/git2-rs that referenced this issue Jun 25, 2020
kim added a commit to kim/git2-rs that referenced this issue Jun 25, 2020
Previously, the propagated error from a custom transport would always be the
default "unknown error" as returned by `Error::last_error` if `git_error_last`
returns a null pointer. The attached test case is rather trivial, but can be
used to reproduce the old and new behaviour.
kim added a commit to kim/git2-rs that referenced this issue Jun 25, 2020
alexcrichton pushed a commit that referenced this issue Jun 25, 2020
Previously, the propagated error from a custom transport would always be the
default "unknown error" as returned by `Error::last_error` if `git_error_last`
returns a null pointer. The attached test case is rather trivial, but can be
used to reproduce the old and new behaviour.
alexcrichton pushed a commit that referenced this issue Jun 26, 2020
* Add modifiers for error code and class (#576)

* Add `Error::new` constructor and make setters return unit

* Cover new variants

* Adjust transport test case
@kim
Copy link
Contributor Author

kim commented Jun 27, 2020

Closed via #577, #579, #580

@kim kim closed this as completed Jun 27, 2020
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

No branches or pull requests

2 participants