-
-
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
Conversation
Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
gix-url::Url type.
To keep it simple, it feels like everything that is relatively easy to use can be pub field: type, and things that have more constraints on them can be done with setters ma...
gix-url/src/lib.rs
Outdated
| /// when fields are modified directly. The URL should be accepted as a parameter directly rather | ||
| /// than being reconstructed, to maintain validity guarantees. |
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 Make clear that the URL to accept in parameters should always be parsed to this type, but never be an instance of this type.
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 the mutability warning to clarify that URLs should always be parsed to this type from string or byte parameters, but never be accepted as an instance of this type and then reconstructed. Commit: f1e98e5
Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
|
@copilot Find all occurrences of |
Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
I've found and replaced all 4 occurrences of
All tests pass and the workspace builds successfully. Commit: fbe454e |
gix-url/src/lib.rs
Outdated
| (None, None) => {} | ||
| (Some(_user), None) => unreachable!("BUG: should not be possible to have a user but no host"), | ||
| (Some(_user), None) => { | ||
| return Err(std::io::Error::new( |
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 of std::io::Error::new(). Commit: c29bd0a
gix-url/src/parse.rs
Outdated
| #[error("URL has invalid structure: user specified without host")] | ||
| InvalidUrlStructure, |
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 Remove this change - this unreachable! is actually unreachable.
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.
Reverted the changes to parse.rs - the unreachable! in From<Infallible> implementation is kept as originally intended since it's actually unreachable. Commit: c29bd0a
gix-url/tests/url/expand_path.rs
Outdated
| 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 | ||
| }, |
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 remove change - don't touch tests.
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.
Reverted the test changes in expand_path.rs - the original test with unreachable!("we have a name") is restored. Commit: c29bd0a
Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
This PR makes all
Urlstruct fields public to allow direct manipulation of URL components, while ensuring the codebase handles invalid URL states gracefully.Changes Made
Public Fields
Urlfields (scheme,user,password,host,serialize_alternative_form,port,path) public for direct access and modificationDocumentation
Error Handling
unreachable!calls in URL serialization methods with properstd::io::Error::other()for invalid user-without-host combinationsFrom<Infallible>implementation (keeping originalunreachable!as it's actually unreachable)std::io::Error::other()where possibleNow that URL fields are public and can have any state, the codebase handles URL serialization edge cases with appropriate errors instead of panics, while maintaining the existing behavior for truly unreachable code paths.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.