Skip to content

Report missing AWS credentials as an error, not a panic; lint against unwrap() - #45

Merged
mdub merged 1 commit into
mainfrom
mdub-20261111-clippy-unwrap-used
Nov 11, 2026
Merged

mdub merged 1 commit into
mainfrom
mdub-20261111-clippy-unwrap-used

Conversation

@mdub

@mdub mdub commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Running bergr glue, bergr from s3://… or bergr rest --auth sigv4 without usable AWS credentials no longer panics. It now prints an error naming each credential provider that was tried and why it failed, and exits 1:

ERROR: AWS credentials not configured: the credential provider was not enabled: no credentials found in chain. Attempted:
  Environment: the credential provider was not enabled: environment variable not set
  Profile: the credential provider was not enabled: profile `nope` was not defined: could not find source profile nope referenced from the root profile

Before, it panicked in get_aws_config(), dumped CredentialsNotLoaded(CredentialsNotLoaded { source: Some(ProviderChainError { … }) }) and exited 101.

The PR also enables clippy::unwrap_used, with allow-unwrap-in-tests. CI already runs clippy with -D warnings, so new unwrap()s in production code will fail the build. The only existing ones were four parse().unwrap()s on hard-coded tracing directives in main.rs. These now go through a single expect that states the invariant.

Changes

  • src/aws.rs: get_aws_config() returns Result. The check moves into check_credentials(), which returns an ExpectedError. The source chain is formatted with anyhow's {:#}, which shows each cause without a Debug dump.
  • src/main.rs: the callers propagate the error with ?. The --debug tracing targets are now a DEBUG_TARGETS list, folded into the EnvFilter.
  • Cargo.toml and clippy.toml: turn on the lint, allowing it in tests.

Testing

  • cargo fmt, cargo clippy --all-targets -- -D warnings and cargo test (61 tests) pass. The new tests cover a provider that fails and one that works.
  • Checked by hand with no credentials, with an undefined AWS_PROFILE, and with a working profile against a real Glue catalog. The --debug output matches main's.

…ainst unwrap()

get_aws_config() panicked when no AWS credentials could be found, printing a
Debug dump and exiting 101. It now returns an ExpectedError naming each
provider that was tried and why it failed, and exits 1.

Enable clippy::unwrap_used (allowed in tests), so CI rejects new unwrap()s in
production code, and replace the four in main.rs's tracing setup.
@mdub
mdub merged commit 4c5aa65 into main Nov 11, 2026
4 checks passed
@mdub
mdub deleted the mdub-20261111-clippy-unwrap-used branch November 13, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant