Skip to content

fix: exit non-zero when setup aws fails to write the profile#349

Merged
gtsiolis merged 1 commit into
mainfrom
devx-944-lstk-setup-aws-exits-0-when-it-cannot-write-the-aws-profile
Jul 1, 2026
Merged

fix: exit non-zero when setup aws fails to write the profile#349
gtsiolis merged 1 commit into
mainfrom
devx-944-lstk-setup-aws-exits-0-when-it-cannot-write-the-aws-profile

Conversation

@gtsiolis

Copy link
Copy Markdown
Member

Closes DEVX-944.

lstk setup aws (and the deprecated lstk config profile) reported success and exited 0 even when it failed to write the LocalStack AWS profile. Writing the profile is the command's whole purpose, but awsconfig.Setup emitted a warning and returned nil when the write itself failed (read-only ~/.aws, permission denied, full disk, or a corrupt existing ini). The profile was never written, yet the process exited 0 — masking the failure from users, CI, and agents, so downstream aws --profile localstack calls then failed confusingly.

Setup now takes an explicit flag:

  • User-invoked commands (lstk setup aws, lstk config profile) emit a structured ErrorEvent and return a SilentError on a write failure → exit 1.
  • Best-effort post-start path (EnsureProfile during lstk start) keeps warning and continuing, so a profile-write hiccup never aborts an already-running emulator.

Tests

test/integration/awsconfig_test.go adds a case that makes ~/.aws read-only, confirms the prompt, and asserts a non-zero exit — it fails before this change and passes after. (Skipped under root, where directory permissions are bypassed.)

Context

Split out of #346 (DEVX-941), which stays focused on invalid-usage exit codes. This is a sibling instance of the same "prints an error yet exits 0" class, in a different command.

@gtsiolis gtsiolis requested a review from a team as a code owner June 30, 2026 08:53
@gtsiolis gtsiolis self-assigned this Jun 30, 2026
@gtsiolis gtsiolis added semver: patch docs: skip Pull request does not require documentation changes labels Jun 30, 2026

@anisaoshafi anisaoshafi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 🐛

Writing the LocalStack AWS profile is the whole purpose of `lstk setup aws` (and the deprecated `lstk config profile`), but awsconfig.Setup emitted a warning and returned nil when the write itself failed — so a read-only ~/.aws, a permission error, or a full disk left the profile unwritten while the process still exited 0, masking the failure from users, CI, and agents. This is the same "prints an error yet exits 0" class as DEVX-941, in a real command.

Thread an `explicit` flag through Setup: the user-invoked commands now emit a structured ErrorEvent and return a SilentError on a write failure (exit 1), while the best-effort post-start convenience path (EnsureProfile during `lstk start`) keeps warning and continuing so a profile-write hiccup never aborts an already-running emulator.

Add an integration test that makes ~/.aws read-only, confirms the prompt, and asserts a non-zero exit (fails before this change, passes after).
@gtsiolis gtsiolis force-pushed the devx-944-lstk-setup-aws-exits-0-when-it-cannot-write-the-aws-profile branch from e2880eb to 8662b29 Compare July 1, 2026 07:04
@gtsiolis gtsiolis merged commit 009b3f3 into main Jul 1, 2026
13 checks passed
@gtsiolis gtsiolis deleted the devx-944-lstk-setup-aws-exits-0-when-it-cannot-write-the-aws-profile branch July 1, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs: skip Pull request does not require documentation changes semver: patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants