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

.into_string() does not work well with other error types #10

Closed
blyxxyz opened this issue Dec 11, 2021 · 2 comments
Closed

.into_string() does not work well with other error types #10

blyxxyz opened this issue Dec 11, 2021 · 2 comments

Comments

@blyxxyz
Copy link
Owner

blyxxyz commented Dec 11, 2021

Some programs parse inside a function that returns an anyhow-style error type or a custom error type. This doesn't play well with OsString::into_string(): its error type (OsString) can convert to anyhow::Error but not to most other error types.

  • rres uses .into_string().unwrap().
  • minoru-fediverse-crawler uses .into_string().map_err(|ostr| anyhow!("{}", ostr.to_string_lossy()))?.
  • Another workaround would be .into_string().map_err(lexopt::Error::from)?.
  • Yet another is .parse()?. This performs a copy.

A ValueExt::string(self) -> Result<String, lexopt::Error> method would solve this. (There may be a better name.)

Error's From<OsString> impl should then be kept, except perhaps in a release that already breaks most code for other reasons. But it should be removed from the README.

@blyxxyz
Copy link
Owner Author

blyxxyz commented Dec 31, 2022

I've implemented ValueExt::string() in 8b1bfc2.

@blyxxyz
Copy link
Owner Author

blyxxyz commented Jan 16, 2023

ValueExt::string() has been released in v0.3.0.

@blyxxyz blyxxyz closed this as completed Jan 16, 2023
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

1 participant