Skip to content

Conversation

@christerswahn
Copy link
Collaborator

@christerswahn christerswahn commented Feb 25, 2025

BREAKING CHANGES:
Upon argument parse errors the UsageException was replaced by an ExitException.
This behavior is now changed to rethrow the original UsageException instead.

Summary by CodeRabbit

  • Refactor

    • Revised how command execution errors are handled, simplifying error reporting to users.
    • Applied consistent internal formatting improvements to enhance code clarity without changing functionality.
  • Chores

    • Updated continuous integration settings to leverage the latest Dart SDK for improved build and test performance.
  • Bug Fixes

    • Adjusted test cases to reflect changes in error handling, ensuring accurate exception expectations.
    • Enhanced test descriptions for improved readability without altering logic.

BREAKING CHANGES: Upon argument parse errors the UsageException was replaced by an ExitException.
This behavior is now changed to rethrow the orginal UsageException instead.
@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2025

📝 Walkthrough

Walkthrough

This pull request primarily introduces formatting improvements and minor refactoring across several modules and tests. The changes include reformatting constructor initializations, adjusting indentation, and updating test descriptions. A key functional change is in the command runner’s error handling: the parse and runCommand methods now rethrow caught exceptions (specifically UsageException) instead of throwing a custom ExitException. Additionally, the CI workflow has been updated to use a newer Dart setup action with a specified SDK version.

Changes

File(s) Change Summary
lib/.../better_command_runner.dart Removed unused import for exit_exception.dart; reformatted the SetLogLevel typedef and constructor initialization; updated error handling in parse and runCommand to rethrow exceptions instead of throwing an ExitException.
lib/.../better_command.dart Adjusted indentation in the constructor's initialization list.
lib/.../std_out_logger.dart Modified the constructor’s initialization list and _log method formatting for improved readability.
lib/.../analytics.dart Reformatted constructor field initialization and _quietPost method invocation without changing functionality.
lib/.../package_version.dart
lib/.../pub_api_client.dart
Updated parameter indentation and return statement formatting for enhanced clarity.
lib/.../confirm.dart
lib/.../select.dart
Refactored the prompt variable assignment and reformatted method calls/conditional expressions to improve code readability.
lib/.../progress.dart Applied a minor formatting adjustment in the constructor’s parameter list.
.github/workflows/ci.yml Upgraded Dart setup action from v1.6.4 to v1.7.1 and specified the Dart SDK version as 3.6.
Test Files:
test/.../exit_exceptions_test.dart
test/.../multiple_select_test.dart
test/.../select_test.dart
test/.../local_storage_manager_test.dart
test/.../package_version_test.dart
test/.../confirm_test.dart
test/.../input_test.dart
Updated tests to expect UsageException instead of ExitException; reformatted test descriptions with improved line breaks and indentation; expanded error assertions to include exit code checks in specific cases.
Test Utilities:
test/.../io_helper.dart
test/.../mock_stdin.dart
Adjusted function signature and constructor parameter indentations for consistent formatting.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant BCR as BetterCommandRunner
    participant C as Command

    U->>BCR: runCommand(args)
    BCR->>C: execute command
    C-->>BCR: throws UsageException
    BCR->>U: rethrow UsageException
Loading

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75a97a2 and 90388d4.

📒 Files selected for processing (7)
  • lib/src/better_command_runner/better_command_runner.dart (5 hunks)
  • lib/src/logger/helpers/ansi_style.dart (1 hunks)
  • lib/src/logger/loggers/std_out_logger.dart (2 hunks)
  • test/better_command_runner/exit_exceptions_test.dart (1 hunks)
  • test/prompts/multiple_select_test.dart (12 hunks)
  • test/prompts/select_test.dart (10 hunks)
  • test/std_out_logger_test.dart (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • test/prompts/multiple_select_test.dart
  • lib/src/logger/helpers/ansi_style.dart
🔇 Additional comments (23)
test/better_command_runner/exit_exceptions_test.dart (3)

35-44: Tests properly enforce thrown UsageException for unknown command.

This aligns with the new behavior of rethrowing UsageException.


47-56: Tests properly enforce thrown UsageException for invalid command.

This ensures consistent behavior across different invalid arguments scenarios.


59-68: Tests correctly handle UsageException for missing mandatory options.

Validating missing arguments is now consistent with the updated usage exception logic.

test/prompts/select_test.dart (11)

12-15: Multi-line test description refactor.

No functional changes; the readability improvement is approved.


30-33: Multi-line test description refactor.

No functional changes.


48-51: Multi-line test description refactor.

No functional changes.


62-65: Multi-line test description refactor.

Approved as-is.


76-79: Multi-line test description refactor.

Approved change.


98-101: Multi-line test description refactor.

Approved with no objections.


108-117: Verify consistency between ExitException usage and the removal of ExitException in other parts.

The rest of the codebase rethrows UsageException, yet pressing "q" triggers an ExitException. Confirm whether this is intentional for user cancellation or if it should align with the new logic.


120-123: Multi-line test description refactor.

Looks good.


130-133: Multi-line test description refactor.

No functional changes.


155-157: Multi-line test description refactor.

No objections here.


177-179: Multi-line test description refactor.

Approved.

test/std_out_logger_test.dart (2)

1-49: Sufficient coverage testing default logger behavior.

Verifying output to stdout for all log levels is thorough.


51-96: Validates redirection to stderr above warning level.

Tests confirm that warning and error logs are routed correctly to stderr.

lib/src/better_command_runner/better_command_runner.dart (4)

16-19: Formatting of typedef is acceptable.

No functional change introduced; readability is fine.


64-69: Constructor reformat maintains existing logic.

No further concerns.


119-119: Rethrowing UsageException preserves original details.

Switching from throwing a custom exit exception to rethrowing UsageException improves debugging accuracy.


175-175: Consistent rethrow of UsageException in runCommand.

This aligns with the updated error-handling strategy throughout the runner.

lib/src/logger/loggers/std_out_logger.dart (3)

17-20: Clear documentation for the new parameter

The documentation clearly explains the purpose of the new logToStderrLevelThreshold parameter and its default behavior.


211-217: Clean implementation of the new stdout/stderr routing logic

The implementation properly checks if the threshold is set before routing messages to stderr, aligning with the PR objective to make logging to stderr opt-in instead of the default behavior.


204-207: Minor formatting adjustment for improved readability

No functional changes in this segment, just improved indentation for better code readability.

@SandPod
Copy link
Contributor

SandPod commented Feb 25, 2025

This PR introduces multiple unrelated changes.

To preserve a valid commit history in main, be able to utilize automatically generated changelogs, and support "git bisect" if breaking changes are introduced. Please separate these changes into different PRs.

I think this is especially important since there are two separate breaking changes, Changed default behavior to use stdout and preserve UsageException.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
.github/workflows/ci.yml (2)

16-21: CI Workflow (Dart Format Job): Updated Dart Setup Action & YAML Indentation

The update to use dart-lang/setup-dart@v1.7.1 with SDK version 3.7 in the dart_format job looks appropriate. However, YAML linting flagged an indentation issue on line 19 (expected 18 spaces but found 16). Please adjust the indentation to conform to YAML standards.

-                sdk: 3.7
+                  sdk: 3.7
🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 19-19: wrong indentation: expected 18 but found 16

(indentation)


27-29: CI Workflow (Dart Analyze Job): Updated Dart Setup Action & Indentation Warning

The dart_analyze job now uses dart-lang/setup-dart@v1.7.1 which is consistent with our updated setup. Note that the YAML lint warning on line 29 indicates that the indentation is off (expected 18 spaces). Please fix the indentation.

-                sdk: 3.7
+                  sdk: 3.7
🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 29-29: wrong indentation: expected 18 but found 16

(indentation)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90388d4 and 8c47920.

📒 Files selected for processing (17)
  • .github/workflows/ci.yml (2 hunks)
  • lib/src/analytics/analytics.dart (2 hunks)
  • lib/src/better_command_runner/better_command.dart (1 hunks)
  • lib/src/logger/helpers/progress.dart (1 hunks)
  • lib/src/logger/loggers/std_out_logger.dart (2 hunks)
  • lib/src/package_version/package_version.dart (3 hunks)
  • lib/src/package_version/pub_api_client.dart (1 hunks)
  • lib/src/prompts/confirm.dart (1 hunks)
  • lib/src/prompts/select.dart (3 hunks)
  • test/local_storage_manager/local_storage_manager_test.dart (11 hunks)
  • test/package_version_test.dart (3 hunks)
  • test/prompts/confirm_test.dart (13 hunks)
  • test/prompts/input_test.dart (6 hunks)
  • test/prompts/multiple_select_test.dart (12 hunks)
  • test/prompts/select_test.dart (10 hunks)
  • test/test_utils/io_helper.dart (1 hunks)
  • test/test_utils/mock_stdin.dart (1 hunks)
✅ Files skipped from review due to trivial changes (13)
  • test/prompts/confirm_test.dart
  • lib/src/prompts/confirm.dart
  • lib/src/package_version/pub_api_client.dart
  • test/package_version_test.dart
  • test/prompts/input_test.dart
  • test/test_utils/io_helper.dart
  • lib/src/logger/helpers/progress.dart
  • lib/src/analytics/analytics.dart
  • lib/src/better_command_runner/better_command.dart
  • test/test_utils/mock_stdin.dart
  • lib/src/prompts/select.dart
  • lib/src/package_version/package_version.dart
  • test/local_storage_manager/local_storage_manager_test.dart
🚧 Files skipped from review as they are similar to previous changes (3)
  • lib/src/logger/loggers/std_out_logger.dart
  • test/prompts/multiple_select_test.dart
  • test/prompts/select_test.dart
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/ci.yml

[warning] 19-19: wrong indentation: expected 18 but found 16

(indentation)


[warning] 29-29: wrong indentation: expected 18 but found 16

(indentation)


[warning] 39-39: wrong indentation: expected 18 but found 16

(indentation)

@christerswahn christerswahn changed the title feat!: Changed default behavior to use stdout & preserve UsageException feat!: Preserves UsageException instead of replacing it with ExitException Feb 25, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
.github/workflows/ci.yml (1)

36-40: ⚠️ Potential issue

Inconsistent Setup Action Version & Indentation in Dart Test Job
The Dart Test job still uses dart-lang/setup-dart@v1.6.4 (line 37) whereas the other jobs have been updated to v1.7.1. This inconsistency could lead to unexpected CI behavior. Additionally, the sdk parameter on line 39 is indented with 16 spaces instead of 18. Aligning the version and indentation with the other jobs will ensure uniform behavior across your CI pipeline.

-            - uses: dart-lang/setup-dart@v1.6.4
+            - uses: dart-lang/setup-dart@v1.7.1
-                sdk: 3.7
+                  sdk: 3.7
🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 39-39: wrong indentation: expected 18 but found 16

(indentation)


[error] 40-40: no new line character at the end of file

(new-line-at-end-of-file)

🧹 Nitpick comments (2)
.github/workflows/ci.yml (2)

16-21: Indentation Issue in Dart Format Job
The sdk parameter under the with: block (line 19) is indented with 16 spaces instead of the expected 18 spaces according to YAMLlint. Correcting the indentation will help avoid potential YAML parsing issues.

-                sdk: 3.7
+                  sdk: 3.7
🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 19-19: wrong indentation: expected 18 but found 16

(indentation)


27-29: Indentation Issue in Dart Analyze Job
The sdk parameter (line 29) in the Dart Analyze job is indented with 16 spaces while YAMLlint expects 18 spaces. Please adjust this indentation for consistency and to prevent lint warnings.

-                sdk: 3.7
+                  sdk: 3.7
🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 29-29: wrong indentation: expected 18 but found 16

(indentation)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c47920 and 8a9c2e7.

📒 Files selected for processing (17)
  • .github/workflows/ci.yml (2 hunks)
  • lib/src/analytics/analytics.dart (2 hunks)
  • lib/src/better_command_runner/better_command.dart (1 hunks)
  • lib/src/logger/helpers/progress.dart (1 hunks)
  • lib/src/logger/loggers/std_out_logger.dart (2 hunks)
  • lib/src/package_version/package_version.dart (3 hunks)
  • lib/src/package_version/pub_api_client.dart (1 hunks)
  • lib/src/prompts/confirm.dart (1 hunks)
  • lib/src/prompts/select.dart (3 hunks)
  • test/local_storage_manager/local_storage_manager_test.dart (11 hunks)
  • test/package_version_test.dart (3 hunks)
  • test/prompts/confirm_test.dart (13 hunks)
  • test/prompts/input_test.dart (6 hunks)
  • test/prompts/multiple_select_test.dart (12 hunks)
  • test/prompts/select_test.dart (10 hunks)
  • test/test_utils/io_helper.dart (1 hunks)
  • test/test_utils/mock_stdin.dart (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (16)
  • lib/src/package_version/pub_api_client.dart
  • test/test_utils/mock_stdin.dart
  • test/prompts/confirm_test.dart
  • test/package_version_test.dart
  • lib/src/logger/helpers/progress.dart
  • test/prompts/input_test.dart
  • lib/src/prompts/confirm.dart
  • lib/src/prompts/select.dart
  • lib/src/package_version/package_version.dart
  • lib/src/better_command_runner/better_command.dart
  • test/prompts/select_test.dart
  • test/local_storage_manager/local_storage_manager_test.dart
  • test/test_utils/io_helper.dart
  • test/prompts/multiple_select_test.dart
  • lib/src/logger/loggers/std_out_logger.dart
  • lib/src/analytics/analytics.dart
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/ci.yml

[warning] 19-19: wrong indentation: expected 18 but found 16

(indentation)


[warning] 29-29: wrong indentation: expected 18 but found 16

(indentation)


[warning] 39-39: wrong indentation: expected 18 but found 16

(indentation)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
.github/workflows/ci.yml (4)

19-19: Fix YAML indentation for Dart SDK version specification (dart_format job).

Static analysis reports that line 19 is indented with 16 spaces while 18 spaces are expected. Please adjust the indentation to ensure proper YAML formatting.

-                sdk: 3.6
+                  sdk: 3.6
🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 19-19: wrong indentation: expected 18 but found 16

(indentation)


29-29: Fix YAML indentation for Dart SDK version specification (dart_analyze job).

Line 29 is mis-indented (16 spaces instead of 18). Increasing the indentation will resolve the YAML lint warning.

-                sdk: 3.6
+                  sdk: 3.6
🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 29-29: wrong indentation: expected 18 but found 16

(indentation)


39-39: Fix YAML indentation for Dart SDK version specification (dart_test job).

The static analysis indicates that line 39 has insufficient indentation. Please update it to 18 spaces.

-                sdk: 3.6
+                  sdk: 3.6
🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 39-39: wrong indentation: expected 18 but found 16

(indentation)


40-40: Ensure the file ends with a newline.

The linter notes that there's no newline at the end of the file. Please add a newline to conform with best practices.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 40-40: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d822c90 and bc8ca52.

📒 Files selected for processing (17)
  • .github/workflows/ci.yml (1 hunks)
  • lib/src/analytics/analytics.dart (2 hunks)
  • lib/src/better_command_runner/better_command.dart (1 hunks)
  • lib/src/logger/helpers/progress.dart (1 hunks)
  • lib/src/logger/loggers/std_out_logger.dart (2 hunks)
  • lib/src/package_version/package_version.dart (3 hunks)
  • lib/src/package_version/pub_api_client.dart (1 hunks)
  • lib/src/prompts/confirm.dart (1 hunks)
  • lib/src/prompts/select.dart (3 hunks)
  • test/local_storage_manager/local_storage_manager_test.dart (11 hunks)
  • test/package_version_test.dart (3 hunks)
  • test/prompts/confirm_test.dart (13 hunks)
  • test/prompts/input_test.dart (6 hunks)
  • test/prompts/multiple_select_test.dart (12 hunks)
  • test/prompts/select_test.dart (10 hunks)
  • test/test_utils/io_helper.dart (1 hunks)
  • test/test_utils/mock_stdin.dart (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (16)
  • lib/src/logger/loggers/std_out_logger.dart
  • test/local_storage_manager/local_storage_manager_test.dart
  • lib/src/package_version/pub_api_client.dart
  • lib/src/better_command_runner/better_command.dart
  • test/prompts/input_test.dart
  • test/prompts/confirm_test.dart
  • lib/src/prompts/confirm.dart
  • lib/src/prompts/select.dart
  • lib/src/logger/helpers/progress.dart
  • lib/src/analytics/analytics.dart
  • test/package_version_test.dart
  • test/prompts/multiple_select_test.dart
  • lib/src/package_version/package_version.dart
  • test/test_utils/io_helper.dart
  • test/test_utils/mock_stdin.dart
  • test/prompts/select_test.dart
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/ci.yml

[warning] 19-19: wrong indentation: expected 18 but found 16

(indentation)


[warning] 29-29: wrong indentation: expected 18 but found 16

(indentation)


[warning] 39-39: wrong indentation: expected 18 but found 16

(indentation)

🔇 Additional comments (1)
.github/workflows/ci.yml (1)

17-21: Confirm the intended Dart SDK version across CI jobs.

All jobs now specify sdk: 3.6 with dart-lang/setup-dart@v1.7.1. Please verify that Dart SDK 3.6 is the expected version, as previous guidance mentioned version 3.7. Consistency in the target Dart SDK version is important for uniform CI behavior.

🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 19-19: wrong indentation: expected 18 but found 16

(indentation)

Copy link
Contributor

@SandPod SandPod left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@christerswahn christerswahn merged commit 1df6935 into main Feb 25, 2025
4 checks passed
@christerswahn christerswahn deleted the 646-errors branch February 25, 2025 13:25
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.

3 participants