Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: Preventing log enrichment for bare mode #3916

Merged

Conversation

yhakbar
Copy link
Collaborator

@yhakbar yhakbar commented Feb 21, 2025

Description

Fixes #3885.

TODOs

Read the Gruntwork contribution guidelines.

  • Update the docs.
  • Run the relevant tests successfully, including pre-commit checks.
  • Ensure any 3rd party code adheres with our license policy or delete this line if its not applicable.
  • Include release notes. If this PR is backward incompatible, include a migration guide.

Release Notes (draft)

Updated log-format auto-adjustment in options.

Migration Guide

Summary by CodeRabbit

  • Bug Fixes
    • Improved flag handling to ensure default values are always initialized, reducing the risk of runtime errors.
  • Tests
    • Added an integration test to verify that the log output for the bare format option is displayed correctly.

Copy link

vercel bot commented Feb 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
terragrunt-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 21, 2025 6:03pm

Copy link
Contributor

coderabbitai bot commented Feb 21, 2025

Walkthrough

This pull request enhances robustness in CLI flag handling by ensuring that the Destination pointer for both boolean and generic flags is never nil before use. The Apply methods in both BoolFlag and GenericFlag now include conditional checks to initialize Destination if it is nil. Corresponding test cases have been updated to confirm that the default values are set from the initialized destination. Additionally, an integration test has been added to verify that using the --log-format=bare option produces the expected logging output.

Changes

File(s) Change Summary
internal/cli/…/bool_flag.go
internal/cli/…/bool_flag_test.go
Added conditional logic in the Apply method to initialize Destination if it’s nil in BoolFlag and updated tests to verify that the value is correctly assigned.
internal/cli/…/generic_flag.go
internal/cli/…/generic_flag_test.go
Implemented a similar nil-check in the Apply method for GenericFlag to ensure Destination is initialized, with tests updated to confirm the expected behavior when default values are assigned.
test/…/integration_test.go Introduced a new test function to check that the terragrunt init command produces the expected bare logging output when using the --log-format=bare option by verifying specific log message content.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant BoolFlagApply as BoolFlag.Apply
    Caller->>BoolFlagApply: Call Apply()
    BoolFlagApply->>BoolFlagApply: Check if Destination is nil?
    alt Destination is nil
      BoolFlagApply->>BoolFlagApply: Initialize Destination = new(bool)
    end
    BoolFlagApply->>BoolFlagApply: Create value via newBoolVar & newGenericValue
    BoolFlagApply->>Caller: Return updated flag
Loading
sequenceDiagram
    participant Caller
    participant GenericFlagApply as GenericFlag.Apply
    Caller->>GenericFlagApply: Call Apply()
    GenericFlagApply->>GenericFlagApply: Check if Destination is nil?
    alt Destination is nil
      GenericFlagApply->>GenericFlagApply: Initialize Destination = new(T)
    end
    GenericFlagApply->>GenericFlagApply: Create genericVar[T] & genericValue
    GenericFlagApply->>Caller: Return updated flag
Loading

Possibly related PRs

Suggested reviewers

  • denis256
  • yhakbar

Poem

In the realm of flags where errors hide,
We tame the nil with care and pride.
Pointers now shine with proper light,
Tests affirm the code is right.
Cheers to cleaner, safer calls—
Our code now stands tall through it all!
🚀 Happy coding!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3613716 and 8b7f9e4.

📒 Files selected for processing (5)
  • internal/cli/bool_flag.go (1 hunks)
  • internal/cli/bool_flag_test.go (1 hunks)
  • internal/cli/generic_flag.go (1 hunks)
  • internal/cli/generic_flag_test.go (1 hunks)
  • test/integration_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Pull Request has non-contributor approval
  • GitHub Check: build-and-test
  • GitHub Check: Pull Request has non-contributor approval
🔇 Additional comments (5)
internal/cli/bool_flag.go (1)

47-49: Nice defensive programming! 🛡️

Good catch on initializing the Destination pointer when it's nil. This matches the existing protection in RunAction and prevents potential crashes.

internal/cli/bool_flag_test.go (1)

125-129: Test changes align perfectly with the implementation! ✅

The test now properly validates the nil Destination handling behavior. Moving the expectedDefaultValue assignment after initialization ensures we're testing the actual behavior.

internal/cli/generic_flag.go (1)

49-51: Consistent nil handling across flag types! 👍

Great job applying the same defensive programming pattern to generic flags. This creates a nice, consistent behavior across all flag types.

internal/cli/generic_flag_test.go (1)

190-194: Tests are consistently thorough! 🎯

The test changes properly validate the nil Destination handling for generic flags, maintaining the same robust testing pattern we see in the boolean flag tests.

test/integration_test.go (1)

4116-4129: Great test implementation for the bare log format feature!

The test effectively verifies that bare log format preserves raw log messages without enrichment. Clean setup with proper cleanup, parallel execution, and clear assertions.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 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.

@yhakbar yhakbar merged commit 237f07a into main Feb 21, 2025
8 of 9 checks passed
@yhakbar yhakbar deleted the yousif/tg-976-073x-broke-terragrunt_log_formattg_log_formatbare branch February 21, 2025 18:36
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0.73.x broke TERRAGRUNT_LOG_FORMAT/TG_LOG_FORMAT=bare
2 participants