Skip to content

feat: make GzBuilder::filename and GzBuilder::comment results #463

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

Closed

Conversation

CosminPerRam
Copy link
Contributor

@CosminPerRam CosminPerRam commented Feb 13, 2025

To handle possible panics with user-povided input, return a Result on GzBuilder::comment and GzBuilder::filename.

We build a CString, and if it fails, it returns a NulError which converts to io::Error as an InvalidInput.

Doing so will cause breaking api changes, this is completely debatable if its worth it or not, so this PR is more like a proposal.

For more context:
The unwraps were added here: 6430b38, back in 2015, which makes them 10-years old now.

@jongiddy
Copy link
Contributor

Changing the public API is unlikely to happen. The panic condition is well-documented and can be tested beforehand if the data is provided by the user.

There is a possibility that new Result-returning methods could be added, such as with_filename but, if this is done, it would be worth discussing which type is most appropriate. Passing a CString directly would work and avoid any errors. But arguably a PathBuf is a more appropriate type for a filename. The string is encoded in ISO 8859-1 so enforcing this might also be desirable.

@Byron
Copy link
Member

Byron commented Feb 16, 2025

Thanks a lot for proposing this.

But, I agree with @jongiddy that there'd be better ways to accomplish this.
As this PR won't be merged, I suggest, also for the sake of discussion, to create a new PR that adds a new method so making this improvement won't be a breaking change, if there is interest.

Thanks for your understanding.

@Byron Byron closed this Feb 16, 2025
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

Successfully merging this pull request may close these issues.

3 participants