fix(backend-2fa): remove process-terminating expect from AWS provider initialization - #1273
Merged
llinsss merged 2 commits intoAug 31, 2026
Merged
Conversation
… init select_secret_provider() panicked via .expect() if AWS provider construction failed. It now returns Result and propagates a typed error instead, so misconfiguration is reported, not fatal.
|
@rudeus112266 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
select_secret_provider()called.expect("failed to initialise AwsSecretsManagerProvider")onAwsSecretsManagerProvider::new(). Any AWS provider construction failure (e.g. the internal Tokio runtime failing to start) panicked the whole process instead of surfacing an actionable startup error. This propagates the error viaResultinstead.Before / After
select_secret_provider() -> Box<dyn SecretProvider>, panics on AWS init failure.select_secret_provider() -> Result<Box<dyn SecretProvider>, String>, returnsErron AWS init failure.AwsSecretsManagerProvider::new()itself already returnedResultand was not the source of the panic — the panic was solely at this call site.Testing
Added focused tests, run with
cargo test -p petchain-2fa --lib db:::AWS_REGION/AWS_DEFAULT_REGION: construction must not panic (confirmed —aws-config's loader is lazy and doesn't eagerly validate region).AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY: construction succeeds, butget_secretreturnsErr, never panics.get_secret("")returnsErr, never panics.Note:
upstream/main(HEAD2a8656b) currently has 8 pre-existingcargo check -p petchain-2fa --liberrors unrelated to this change (missingenroll_lockfield onTwoFactorHandlers,TenantScopedStorenot implementingTwoFactorStore), and 14 pre-existing errors in the test-cfg build. Verified this diff adds zero additional errors to either baseline.Threat model
A panic on AWS misconfiguration is an availability/DoS risk (crashes the whole process instead of degrading to a clear config error), not a confidentiality or authorization concern — no secret values are included in any new error message.
Closes #1222