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

libgraphviz: Id::new returns Result<Id, ()> instead of panicking on error #18921

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Nov 13, 2014

creating a new Id object requires the format to match a subset of ID format defined by the DOT language. When the format did not match, the function called assert. This was not mentioned in the docs or the spec. I made the failure explicit by returning an Result<Id, ()>.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (or someone else) soon.

@oli-obk
Copy link
Contributor Author

oli-obk commented Nov 13, 2014

sorry, didn't know about make tidy, will fix in a sec... https://github.com/rust-lang/rust/wiki/Note-development-policy#pull-request-procedure should probably be extended to include make tidy

@oli-obk oli-obk force-pushed the refactoring/graphviz/id/new/result_instead_of_fail branch from 0798273 to f4ba7ee Compare November 13, 2014 13:39
@@ -351,14 +351,18 @@ impl<'a> Id<'a> {
/// defined by the DOT language. This function may change in the
/// future to accept a broader subset, or the entirety, of DOT's
/// `ID` format.)
pub fn new<Name:str::IntoMaybeOwned<'a>>(name: Name) -> Id<'a> {
pub fn new<Name:str::IntoMaybeOwned<'a>>(name: Name) -> Result<Id<'a>, ()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update the documentation of this function to include the error cases as well? It's not totally clear when Err would be returned for example.

@oli-obk oli-obk force-pushed the refactoring/graphviz/id/new/result_instead_of_fail branch from f4ba7ee to 6221f7e Compare November 14, 2014 09:47
@@ -346,19 +346,25 @@ impl<'a> Id<'a> {
/// identifier format: it must be a non-empty string made up of
/// alphanumeric or underscore characters, not beginning with a
/// digit (i.e. the regular expression `[a-zA-Z_][a-zA-Z_0-9]*`).
/// Passing different string (i.e. containing spaces, brackets,
/// quotes, ...) will return an empty `Err` value.
///
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcrichton like this or should i create an example?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

@oli-obk oli-obk force-pushed the refactoring/graphviz/id/new/result_instead_of_fail branch from 6221f7e to d0edf59 Compare November 14, 2014 11:47
@oli-obk oli-obk force-pushed the refactoring/graphviz/id/new/result_instead_of_fail branch 5 times, most recently from abbc1cc to 9c06cb7 Compare November 17, 2014 13:54
…rror

creating a new Id object requires the format to match a subset of `ID` format defined by the DOT language. When the format did not match, the function called assert. This was not mentioned in the docs or the spec. I made the failure explicit by returning an Result<Id, ()>.
@oli-obk oli-obk force-pushed the refactoring/graphviz/id/new/result_instead_of_fail branch from 9c06cb7 to 70bf4f7 Compare November 17, 2014 14:08
@oli-obk
Copy link
Contributor Author

oli-obk commented Nov 17, 2014

the tests are now two separate tests (and they compile).
I think i got all avenues covered this time around.
please run the merge again @alexcrichton

@alexcrichton
Copy link
Member

Thanks @oli-obk!

@bors bors merged commit 70bf4f7 into rust-lang:master Nov 18, 2014
@oli-obk oli-obk deleted the refactoring/graphviz/id/new/result_instead_of_fail branch November 18, 2014 12:58
lnicola pushed a commit to lnicola/rust that referenced this pull request Jan 20, 2025
internal: Compute inlay hint text edits lazily
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.

5 participants