8000 Refactor list components and fix lints by Cerebrovinny · Pull Request #1162 · cloudposse/atmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor list components and fix lints #1162

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 25, 2025
Merged

Conversation

Cerebrovinny
Copy link
Collaborator
@Cerebrovinny Cerebrovinny commented Mar 21, 2025

what

Refactor list components for new lint standards

why

I will use this component in furter list components filter development and need to clean this up in order to reduce PR changes
Screenshot 2025-03-21 at 23 14 07
Screenshot 2025-03-21 at 23 14 26

references

Summary by CodeRabbit

  • New Features

    • Enhanced error messaging now provides clearer, more specific feedback when issues arise during component listing.
    • Introduced distinct handling for retrieving components for specific selections as well as aggregating components across all stacks.
  • Bug Fixes

    • Improved error handling in test cases ensures that failures are caught immediately, enhancing test reliability.
  • Tests

    • Expanded test coverage for various scenarios related to stack components, ensuring comprehensive validation of functionality.

@Cerebrovinny Cerebrovinny added patch A minor, backward compatible change and removed size/s labels Mar 21, 2025
@Cerebrovinny Cerebrovinny requested review from osterman and aknysh March 21, 2025 23:15
@Cerebrovinny Cerebrovinny marked this pull request as ready for review March 21, 2025 23:17
@Cerebrovinny Cerebrovinny requested a review from a team as a code owner March 21, 2025 23:17
Copy link
Contributor
coderabbitai bot commented Mar 21, 2025
📝 Walkthrough

Walkthrough

The changes in pkg/list/list_components.go introduce six new error variables and modify the getStackComponents function to return these specific errors. Two new functions, getComponentsForSpecificStack and processAllStacks, are added to improve error handling and component retrieval logic. The FilterAndListComponents function is updated to utilize the new processing function. Overall, these modifications enhance error clarity and modularize the code.

Changes

File Change Summary
pkg/list/list_components.go Added error variables (ErrParseStacks, ErrParseComponents, ErrParseTerraformComponents, ErrStackNotFound, ErrProcessStack), updated error handling in getStackComponents, and introduced two new functions: getComponentsForSpecificStack and processAllStacks.
pkg/list/list_components_test.go Updated error assertions in tests to use require.NoError, added new test functions for getStackComponents, getComponentsForSpecificStack, processAllStacks, and FilterAndListComponents, and changed slice comparison assertions to assert.ElementsMatch.

Suggested labels

minor


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f0e34b and 1584261.

📒 Files selected for processing (1)
  • pkg/list/list_components_test.go (3 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
pkg/list/list_components_test.go (2)
pkg/list/list_components.go (11)
  • FilterAndListComponents (76-102)
  • components (64-64)
  • components (77-77)
  • getStackComponents (26-43)
  • ErrParseStacks (14-14)
  • ErrParseComponents (16-16)
  • ErrParseTerraformComponents (18-18)
  • getComponentsForSpecificStack (46-60)
  • ErrStackNotFound (20-20)
  • ErrProcessStack (22-22)
  • processAllStacks (63-73)
pkg/schema/schema.go (1)
  • ConfigAndStacksInfo (363-431)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: [mock-windows] tests/fixtures/scenarios/complete
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: [k3s] demo-helmfile
  • GitHub Check: [localstack] demo-localstack
  • GitHub Check: Summary
🔇 Additional comments (8)
pkg/list/list_components_test.go (8)

4-4: Good additions to the imports section.

Adding the errors package and require from testify enhances your error handling capabilities.

Also applies to: 8-8


24-24: Improved error handling with require.NoError

Switching from assert.Nil(t, err) to require.NoError(t, err) is a solid change. This ensures tests fail immediately if critical operations fail, preventing misleading test results from subsequent assertions.

Also applies to: 31-33, 45-45, 52-52


55-59: Better slice comparison with ElementsMatch

Using assert.ElementsMatch to compare slices is an improvement as it correctly handles elements regardless of their order in the slice.


62-102: Well-structured test for getStackComponents

This comprehensive test covers both the happy path and error cases for the getStackComponents function. The error checking is thorough with clear validations for each error condition.


104-149: Thorough test coverage for getComponentsForSpecificStack

The test cases effectively validate the component retrieval logic and error handling for specific stacks. Good job checking both the error type with errors.Is and the error message content with assert.Contains.


151-208: Robust testing of processAllStacks

Your test cases for processAllStacks comprehensively cover various scenarios including valid stacks, a mix of valid and invalid stacks, and all invalid stacks. This ensures the function correctly handles edge cases by skipping invalid stacks.


210-269: Complete test coverage for FilterAndListComponents

The test thoroughly validates all aspects of the main FilterAndListComponents function, including specific stack filtering, all-stack processing, and error cases. Good job testing edge cases like nil and empty stack maps.


271-289: Valuable integration test

Adding an integration test that uses actual stack data provides an extra layer of validation. This helps ensure the function works correctly with real-world data structures.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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 or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

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
Contributor
@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 (1)
pkg/list/list_components.go (1)

62-73: Consider adding error logging in processAllStacks.

The function silently skips invalid stacks, which might hide underlying issues. Consider logging these errors or adding a debug option to surface these errors.

func processAllStacks(stacksMap map[string]any) []string {
	var components []string
	for stackName, stackData := range stacksMap {
		stackComponents, err := getStackComponents(stackData)
		if err != nil {
-			continue // Skip invalid stacks.
+			// Log error and continue
+			fmt.Printf("Warning: Skipping invalid stack %s: %v\n", stackName, err)
+			continue
		}
		components = append(components, stackComponents...)
	}
	return components
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b58700 and 95f386f.

📒 Files selected for processing (1)
  • pkg/list/list_components.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (8)
pkg/list/list_components.go (8)

11-23: Good improvement in error handling with specific error variables.

The introduction of these specific error variables makes error handling more robust and explicit throughout the code. Following Go's conventions with "Err" prefix and providing clear documentation for each error type is a solid approach.


28-30: Clean error return using predefined error variable.

Using the new predefined error variable improves consistency. Good job simplifying from generic error messages.


33-35: Consistent error handling with predefined variable.

Updating to use the predefined error enhances maintainability and consistency with the rest of the code.


38-40: Consistent use of predefined error.

Same good improvement as previous error handling changes.


45-60: Well-structured new helper function with appropriate error wrapping.

The new helper function getComponentsForSpecificStack properly encapsulates the logic for extracting components from a specific stack. Good use of error wrapping to provide context.


80-86: Good delegation to helper function.

Extracting the specific stack handling to a dedicated function makes the code more modular and readable.


87-89: Clean delegation to processAllStacks.

Using the new helper function makes the code more modular and easier to maintain. The comment is slightly redundant given the function name but doesn't hurt readability.


91-94: Good organization of component post-processing.

Marking the section as component post-processing with a comment improves readability. The deduplication and sorting steps are clear.

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 21, 2025
Copy link
codecov bot commented Mar 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 27.84%. Comparing base (91d6447) to head (7b5c60c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1162      +/-   ##
==========================================
+ Coverage   27.72%   27.84%   +0.12%     
==========================================
  Files         182      182              
  Lines       21132    21145      +13     
==========================================
+ Hits         5858     5888      +30     
+ Misses      14324    14312      -12     
+ Partials      950      945       -5     
Flag Coverage Δ
unittests 27.84% <100.00%> (+0.12%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 22, 2025
Copy link
Contributor
@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 (1)
pkg/list/list_components.go (1)

64-75: Consider adding error feedback for skipped stacks.

The function silently skips invalid stacks without any indication to the caller. Consider adding some form of logging or aggregating errors to inform callers about skipped stacks.

 // processAllStacks collects components from all valid stacks.
-func processAllStacks(stacksMap map[string]any) []string {
+func processAllStacks(stacksMap map[string]any) ([]string, []error) {
 	var components []string
+	var skippedErrors []error
 	for _, stackData := range stacksMap {
 		stackComponents, err := getStackComponents(stackData)
 		if err != nil {
+			skippedErrors = append(skippedErrors, err)
 			continue // Skip invalid stacks.
 		}
 		components = append(components, stackComponents...)
 	}
-	return components
+	return components, skippedErrors
}

Then update the caller in FilterAndListComponents:

 	} else {
 		// Process all stacks.
-		components = processAllStacks(stacksMap)
+		components, _ = processAllStacks(stacksMap)
+		// Optionally log or handle the errors
 	}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6fef279 and e0a6f4f.

📒 Files selected for processing (1)
  • pkg/list/list_components.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (4)
pkg/list/list_components.go (4)

11-25: Well-structured error definitions.

The error definitions are clean and follow Go best practices with descriptive messages and proper documentation. Grouping them in a var block improves readability.


27-45: Improved error handling with dedicated error variables.

The function now returns specific error types instead of generic error messages, making it easier for callers to handle different error cases.


47-62: Good extraction of component retrieval logic.

This function effectively encapsulates the logic for stack component retrieval with proper error handling and context. The error wrapping with fmt.Errorf and %w preserves the original error while adding useful context.


77-94: Good refactoring to improve code organization.

The updated function properly delegates to helper functions and adds nil checking for stacksMap. This makes the code more modular and prevents potential nil pointer dereferences.

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 24, 2025
Copy link
Contributor
@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 (2)
pkg/list/list_components.go (2)

62-73: Consider logging skipped errors

The function correctly implements a "best effort" approach by skipping invalid stacks. Consider adding logging when skipping invalid stacks to avoid silently hiding issues that might need attention.

 func processAllStacks(stacksMap map[string]any) []string {
 	var components []string
 	for _, stackData := range stacksMap {
 		stackComponents, err := getStackComponents(stackData)
 		if err != nil {
+			// Consider logging the error here
 			continue // Skip invalid stacks.
 		}
 		components = append(components, stackComponents...)
 	}
 	return components
 }

78-80: Consider a more specific error for nil stacksMap

Using ErrStackNotFound when stacksMap is nil is somewhat misleading as no specific stack is being referenced. Consider adding a dedicated error like ErrNilStacksMap for this specific case.

+// ErrNilStacksMap is returned when the stacks map is nil.
+var ErrNilStacksMap = errors.New("stacks map is nil")

 func FilterAndListComponents(stackFlag string, stacksMap map[string]any) ([]string, error) {
 	var components []string
 	if stacksMap == nil {
-		return nil, fmt.Errorf("%w: %s", ErrStackNotFound, stackFlag)
+		return nil, ErrNilStacksMap
 	}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e0a6f4f and 5f0e34b.

📒 Files selected for processing (1)
  • pkg/list/list_components.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: [localstack] demo-localstack
  • GitHub Check: Summary
🔇 Additional comments (5)
pkg/list/list_components.go (5)

11-23: Strong error handling approach!

The introduction of specific error variables is a solid improvement. It makes error handling clearer and more consistent throughout the codebase and for consumers of this package. Each error has a descriptive message and clear documentation comments.


26-43: Good refactoring of error returns

Replacing generic error messages with the standardized error variables improves consistency and makes error handling more structured.


45-60: Well-structured helper function

This helper function effectively encapsulates the logic for retrieving components from a specific stack. The error wrapping adds context while preserving the original error types, making debugging easier.


83-92: Clean logic separation

Good job refactoring this function to use the new helper functions. The code is now more readable with clearer separation of concerns between handling specific stacks and processing all stacks.


94-102: Solid component processing

The deduplication and sorting of components is maintained properly. The function handles the empty components case correctly.

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 24, 2025
@osterman osterman added the conflict This PR has conflicts label Mar 25, 2025
Copy link
mergify bot commented Mar 25, 2025

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

@mergify mergify bot removed the conflict This PR has conflicts label Mar 25, 2025
@aknysh aknysh added no-release Do not create a new release (wait for additional code changes) and removed patch A minor, backward compatible change labels Mar 25, 2025
Copy link
Member
@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

LGTM

@aknysh aknysh merged commit 6f1d344 into main Mar 25, 2025
61 of 62 checks passed
@aknysh aknysh 8000 deleted the feat/refactor-list-components branch March 25, 2025 16:16
Copy link

These changes were released in v1.168.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-release Do not create a new release (wait for additional code changes) size/m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0