fix(pg-cli): replace unwrap()/panic with user-friendly errors#162
Merged
rubenhensen merged 2 commits intomainfrom May 5, 2026
Merged
fix(pg-cli): replace unwrap()/panic with user-friendly errors#162rubenhensen merged 2 commits intomainfrom
rubenhensen merged 2 commits intomainfrom
Conversation
Closes #156. The pg-cli crate used unwrap() throughout non-test paths, so common failure modes (missing input file, invalid PKG URL, malformed JSON identity, encryption failure) crashed with raw stack traces instead of helpful messages. - exec() in encrypt and decrypt now return anyhow::Result<()> - main returns ExitCode and prints "Error: ..." with full context chain, then exits 1 - Client::new validates the baseurl up front; create_url returns a ClientError instead of panicking on Url::parse / join - ClientError gains InvalidUrl + Display/source impls so anyhow's context chain renders the underlying url::ParseError - print_qr returns Result and propagates serialization errors - decrypt's explicit panic for non-.enc input becomes a returned error; the check is extracted into a small helper for testing - File open/create, metadata, file_name, progress-bar template, and signing-key extraction all use anyhow context for explanations - Adds unit tests for the new helpers (strip_enc_extension, Client::new url validation, create_url join behaviour) Behaviour is otherwise unchanged: same CLI surface, same network calls, same artifact format.
Contributor
|
fix conflicts |
Contributor
Author
|
Dobby has seen master rubenhensen's request! Dobby will fix the conflicts on this PR right away! |
Resolved conflicts in pg-cli/Cargo.toml and pg-cli/src/client.rs: - Adopted main's switch from lazy_static to std::sync::LazyLock (#158). - Kept this branch's anyhow + url dependencies and ClientError/Display impls. - Kept both sets of tests: the new URL validation tests from this branch plus main's headers_contain_client_version test.
Contributor
Author
|
Conflicts resolved in 2a36f0e. Files conflicted: Resolution:
Verified locally:
Reviewer quickstart unchanged: |
rubenhensen
approved these changes
May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #156.
Summary
exec()inencryptanddecryptnow returnanyhow::Result<()>, andmainprintsError: ...with a full context chain on failure (exit code 1) instead of crashing with a panic backtrace.Client::newvalidates the PKG URL up front;create_urlreturns aClientErrorrather than panicking onUrl::parse/Url::join.ClientErrorgains anInvalidUrlvariant plusDisplay/sourceimpls so the context chain renders the underlyingurl::ParseError.panic!indecrypt.rsfor input filenames not ending in.encbecomes a returned error. The check is factored into a smallstrip_enc_extensionhelper so it is unit-testable.File::open/File::create,metadata(),file_name(), progress-bar template construction, and the public-signing-key extraction paths now useanyhowcontext for human-readable messages.print_qrreturnsResultand propagates QR serialization errors.Behaviour is otherwise unchanged: same CLI surface, same network calls, same on-disk artifact format.
Tests
Unit tests added against the new helpers (the behavioural pieces that were extractable without a live PKG):
client::tests::rejects_invalid_baseurl—Client::new("not a url")returnsInvalidUrlinstead of panicking later.client::tests::accepts_valid_baseurl_and_joins_paths—create_urljoins endpoints correctly.client::tests::create_url_joins_with_trailing_slash— joining is robust to a trailing-slash baseurl.decrypt::tests::strips_enc_suffix,rejects_input_without_enc_suffix,rejects_empty_input— the.encfilename check now returns a friendly error and is exercised on both happy and rejection paths.Also smoke-tested manually:
Reviewer quickstart