atmos icon indicating copy to clipboard operation
atmos copied to clipboard

fix: replace logging with proper UI output for user-facing messages

Open osterman opened this issue 5 months ago • 3 comments

what

  • Replace inappropriate use of log.Info() with proper error display and UI output for messages that users must see regardless of logging configuration
  • Fix custom command error messages to properly display available subcommands
  • Convert validation success/failure messages to UI output instead of logs

why

  • When users run invalid subcommands (like atmos dev pr-check), the available subcommands were displayed using log.Info(), which means users get no feedback when logging is disabled
  • Validation messages and other user-facing feedback should always be visible, not dependent on log level settings
  • This violates the principle documented in our logging guidelines that UI output (user interaction) and logging (debugging/telemetry) should be separate

Key Changes

Correctly Changed to UI Output

  • Custom command errors (cmd/cmd_utils.go): Shows available subcommands using proper error formatting
  • Validation results (internal/exec/validate_schema.go): Success/failure messages that users need to see
  • Component validation (cmd/validate_component.go, internal/exec/atmos.go): Success confirmation messages

Correctly Kept as Logging

  • "Executing command" messages: These are debug/informational and should remain as log entries

Testing

  • Added TestUIOutputNotUsingLogging to verify UI messages work with logging disabled
  • Added TestCustomCommandInvalidSubcommand for custom command error display
  • All tests pass with proper stderr output regardless of log level
  • Verified error messages display correctly even with ATMOS_LOGS_LEVEL=Off

references

  • Follows logging guidelines in docs/logging.md
  • closes #1495

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Clearer CLI guidance when a command requires a subcommand: in-line message with valid options and a hint to use --help.
  • Refactor
    • Switched validation and UI feedback from logging to user-facing TUI messages, including success checkmarks and structured error lines.
    • Standardized error output to stderr and reduced logging noise in user messages; no ANSI colors when logging is disabled.
  • Tests
    • Added CLI tests ensuring subcommand guidance, TUI-based validation messages, stderr output, and absence of logging artifacts.

osterman avatar Sep 24 '25 01:09 osterman

[!WARNING]

Rate limit exceeded

@osterman has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 37 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between bd15f9795bf5aae36156050dfc37a757d971a7a5 and 973e28fac7554fbd24034cc1aee2294218499394.

📒 Files selected for processing (7)
  • cmd/cmd_utils_test.go (1 hunks)
  • cmd/validate_component.go (2 hunks)
  • cmd/validate_component_test.go (1 hunks)
  • internal/exec/atmos.go (3 hunks)
  • internal/exec/atmos_test.go (1 hunks)
  • internal/exec/validate_schema.go (2 hunks)
  • internal/exec/validate_schema_test.go (1 hunks)
📝 Walkthrough

Walkthrough

Updates CLI output handling: when a command requires a subcommand, emit a structured “subcommand required” error with usage hint; switch several validation messages from logging to TUI printing; add a new exported error for missing subcommands; add tests verifying stderr-based UI output and absence of log prefixes.

Changes

Cohort / File(s) Summary of Changes
CLI subcommand requirement handling
cmd/cmd_utils.go
Reworked subcommand-required branch to build an inline error describing required subcommand, valid options, and a help hint; now returns via errUtils.CheckErrorPrintAndExit; preserves invalid-command path with augmented messaging.
TUI output for validation (cmd layer)
cmd/validate_component.go
Replaced log.Info success message with u.PrintfMessageToTUI; removed log import, added utils import alias u.
TUI output for validation (exec layer)
internal/exec/atmos.go, internal/exec/validate_schema.go
Switched progress/success/error outputs from logging to u.PrintfMessageToTUI; adjusted formatting for per-file and per-error lines; control flow unchanged.
New error for subcommand requirement
errors/errors.go
Added exported ErrSubcommandRequired = errors.New("subcommand required").
CLI/UI behavior tests
tests/cli_custom_command_test.go, tests/cli_ui_output_test.go
Added tests asserting stderr-only UI output, proper subcommand guidance, absence of log-level prefixes and ANSI color codes when logging is off; verify exit code for invalid subcommand.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant CLI as atmos CLI
  participant CMD as Command Router
  participant ERR as errUtils
  Note over U,CLI: Invoke command that has subcommands but none provided
  U->>CLI: atmos foo
  CLI->>CMD: Parse command path
  CMD->>CMD: Detect missing subcommand
  CMD-->>CLI: Build error with valid subcommands + help hint
  CLI->>ERR: CheckErrorPrintAndExit(error)
  ERR-->>U: Print error to stderr and exit(1)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

Suggested labels

patch

Suggested reviewers

  • aknysh

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning Linked issue #1495 requires XDG cache compliance (ensure $XDG_CACHE_HOME falls back to $HOME/.cache and prevent creating .atmos in unintended locations), but this PR focuses on replacing log.Info with UI output, improving subcommand error messaging, and adding CLI UI tests; there are no changes to cache handling (pkg/config/cache.go) or tests exercising XDG behavior. Because the PR does not modify the cache fallback logic or add verification for XDG behavior, it does not satisfy the objectives of issue #1495. Either remove the link/closing of issue #1495 and treat this as a UI/logging-only fix, or extend the branch to include the XDG cache fallback implementation and tests that verify $XDG_CACHE_HOME falls back to $HOME/.cache; update the PR description accordingly.
Out of Scope Changes Check ⚠️ Warning The changeset primarily updates user-facing messaging and tests (cmd/cmd_utils.go, cmd/validate_component.go, internal/exec/*, errors/errors.go, and new tests) which are unrelated to the XDG/cache objectives of the linked issue; no config or cache-related files were modified. Because the PR claims to close an issue about XDG cache behavior while introducing unrelated UI/logging changes, it contains out-of-scope modifications relative to that linked issue. Recommend splitting concerns: keep UI/logging changes in this PR and remove the XDG issue linkage, or add the required XDG cache fixes and tests in the same branch; ask the author to update the PR description and branch to reflect the chosen approach.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately describes the primary change: replacing logging with proper UI output for user-facing messages; this maps directly to edits in command handling and validation output (cmd/* and internal/exec/*) and the added UI-focused tests. It is concise, specific, and helpful for a teammate scanning PR history.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Sep 24 '25 02:09 coderabbitai[bot]

Codecov Report

:x: Patch coverage is 46.15385% with 7 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 56.98%. Comparing base (6274d75) to head (973e28f). :warning: Report is 239 commits behind head on main.

Files with missing lines Patch % Lines
cmd/cmd_utils.go 0.00% 3 Missing :warning:
cmd/validate_component.go 0.00% 2 Missing :warning:
internal/exec/atmos.go 0.00% 2 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1502      +/-   ##
==========================================
+ Coverage   56.72%   56.98%   +0.26%     
==========================================
  Files         280      284       +4     
  Lines       29708    30290     +582     
==========================================
+ Hits        16851    17261     +410     
- Misses      11045    11201     +156     
- Partials     1812     1828      +16     
Flag Coverage Δ
unittests 56.98% <46.15%> (+0.26%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Sep 24 '25 02:09 codecov[bot]

💥 This pull request now has conflicts. Could you fix it @osterman? 🙏

mergify[bot] avatar Sep 26 '25 05:09 mergify[bot]

💥 This pull request now has conflicts. Could you fix it @osterman? 🙏

mergify[bot] avatar Dec 23 '25 02:12 mergify[bot]