any appetite for `.unwrap()` that prints the err value?
See original GitHub issueOccasionally I have critical errors that cannot be remediated so i’d like to .unwrap(), but I have already captured valuable information in the Result’s Error type that get ignored in the UnwrapError.
Rather than checking for an error, then raising a new error with the captured message I created a .unwrap_print() function (not a great name) to relay this information:
from result import Result, Ok, Err, UnwrapError
from typing import NoReturn
def unwrap_print(self) -> NoReturn:
"""
Raises an `UnwrapError` but prints the error value.
"""
raise UnwrapError(
self,
f"Called `Result.unwrap()` on an `Err` value:: {self.value.__repr__()}",
)
Err.unwrap_print = unwrap_print # type: ignore
>>> f.unwrap_print()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in unwrap_print
result.result.UnwrapError: Called `Result.unwrap()` on an `Err` value:: ValueError('testing')
Is this something that we can either add to the existing .unwrap() method or possibly add as a new method? I’m willing to make the PR but just wanted to see if there were any design constraints you’ve already considered first.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
unwrap()` on an `Err` value: ()', libcore/result.rs:945 ... - GitHub
panicked at 'called `Result::unwrap()` on an `Err` value: ()', libcore/result.rs:945 This seems an old issue, and I saw the fix.
Read more >What is unwrap in Rust, and what is it used for? - Stack Overflow
unwrap() is used here to handle the errors quickly. It can be used on any function that returns Result or Option (Option is...
Read more >Go: the Good, the Bad and the Ugly - Sylvain Wallez
Unwrap() to get the wrapped error. We have to use the separate function errors.Unwrap(err) which uses dynamic typing tests to check if Unwrap ......
Read more >Unwrapping Rust's errors. The Rust programming ... - Medium
unwrap() method can be used on any function that returns a Result<> , and just internally calls a panic, with no error message....
Read more >Spock Framework Reference Documentation
def setupSpec() {} // runs once - before the first feature method def ... As you can see, Spock captures all values produced...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

it looks like the same behavior happens with
.expect("msg")as wellyeah i can make a PR later today!