On Mon, 5 May 2025 at 02:00, Miguel Ojeda miguel.ojeda.sandonis@gmail.com wrote:
On Sun, May 4, 2025 at 7:34 PM Tamir Duberstein tamird@gmail.com wrote:
Why not restrict this to Result<(), E>?
I guess it is an option -- not sure if there may be a use case.
Is it possible to include the error in the output?
I thought about giving some more context somehow and perhaps printing it "manually" in the log, possibly in a KUnit `# ...`. David can probably suggest the "proper" way.
Yeah, writing it to the log is fine: probably the best way of handling this would be to have a kunit assertion macro for "assert_is_ok!()", which prints the error nicely. We could just use the existing kernel::kunit::err() function (which could use some improvement, but is a good start), or even add a proper assertion formatter which handles rust types via %pA.
That being said, there's no guarantee that the Err branch of a Result<> can be printed: so there'd need to be some magic to handle both the case where (e.g.) Err derives Debug, and the case where it doesn't (in which case, we're basically stuck with what we've got here: "expected is_ok()" or similar.
Cheers, -- David