When using `.expect()` in #rustlang, I'm still not confident in what message to write.

Are there any best practices?

Should it describe the error? Or should it describe what was expected? e.g. "Could not read file" vs "Reading file" vs "File is read".

`expect` kinda indicates the latter. But it makes little sense for the consumer who then sees that error.

@berkes I always say what I expect, eg. `.expect("File is readable")`. The error formatting of "panicked at 'File is readable: IOError"" could use some improvement, though.


@berkes Yeah, it confuses me, too, but I also do it like @chrysn does it.

Maybe we should see it this way:
The message in `.expect()` is way more important for the developer than the consumer, because calling `expect` indicates a possible error _that should never happen_.

So the developer will see this far more often than the consumer (actually a consumer should never see this!).

· · Web · 0 · 2 · 2
Sign in to participate in the conversation
Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!