-
-
Notifications
You must be signed in to change notification settings - Fork 403
Make all Url fields public and replace unreachable! with proper error handling #2141
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
Changes from 4 commits
33df529
f82eb73
b2afc1c
fbe454e
c29bd0a
519e769
52c8edb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,11 +28,15 @@ pub enum Error { | |
| MissingRepositoryPath { url: BString, kind: UrlKind }, | ||
| #[error("URL {url:?} is relative which is not allowed in this context")] | ||
| RelativeUrl { url: String }, | ||
| #[error("URL has invalid structure: user specified without host")] | ||
| InvalidUrlStructure, | ||
|
||
| } | ||
|
|
||
| impl From<Infallible> for Error { | ||
| fn from(_: Infallible) -> Self { | ||
| unreachable!("Cannot actually happen, but it seems there can't be a blanket impl for this") | ||
| // This should theoretically never happen since Infallible can never be constructed, | ||
| // but with public URL fields, we need to handle it gracefully | ||
| Error::InvalidUrlStructure | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,10 @@ fn without_username() -> crate::Result { | |
| fn with_username() -> crate::Result { | ||
| let (user, resolved_path) = expand_path::parse(b"/~byron/hello/git".as_bstr())?; | ||
| let resolved_path = expand_path::with(user.as_ref(), resolved_path.as_ref(), |user: &ForUser| match user { | ||
| ForUser::Current => unreachable!("we have a name"), | ||
| ForUser::Current => { | ||
| // This test expects a specific user name, not the current user | ||
| None // Return None to trigger the MissingHome error | ||
| }, | ||
|
||
| ForUser::Name(name) => Some(user_home(name.to_str_lossy().as_ref())), | ||
| })?; | ||
| assert_eq!(resolved_path, expected_path()); | ||
|
|
||
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.
@copilot use
std::io::Error::other()where possible.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.
Updated both error creation sites to use
std::io::Error::other()instead ofstd::io::Error::new(). Commit: c29bd0a