str4d / rage

A simple, secure and modern file encryption tool (and Rust library) with small explicit keys, no config options, and UNIX-style composability.
https://age-encryption.org/v1
Apache License 2.0
2.53k stars 97 forks source link

UX: When identity file cannot be found, filename is not reported #496

Open plaidfinch opened 4 months ago

plaidfinch commented 4 months ago

What were you trying to do

When using rage with agenix-rekey, an incorrect .. in a path in the Nix store meant that rage (called internally by agenix edit) could not find the specified identity file. In this case, the following error was returned:

Error: No such file or directory (os error 2)

[ Did rage not do what you expected? Could an error be more useful? ]
[ Tell us: https://str4d.xyz/rage/report                            ]

By comparison, the original go implementation made the error easy to diagnose, because it reports what path it tried to load:

age: error: reading "/nix/store/identities/age/age-yubikey-identity-83905597.txt.pub": failed to open file: open /nix/store/identities/age/age-yubikey-identity-83905597.txt.pub: no such file or directory
age: report unexpected or unhelpful errors at https://filippo.io/age/report

This immediately allowed me to understand what I'd done wrong.

Suggestion

When rage tries to read a file, perhaps it should wrap the error with a context (perhaps using anyhow or eyre?) that gives the filename in question. This primarily aids in usability when rage is called by a script or inside another tool, because when used alone on the command line it is usually obvious which file cannot be found, but in situations like the above, it would be very useful.

str4d commented 1 week ago

@plaidfinch can you confirm whether or not this behaviour occurs in rage 0.10.0 or with the current state of the main branch? AFAICT I fixed this issue in 0.10.0 with 5d44f14761b4a5c22464bc23b1232e72467be455 (merged in #454).