Skip to content
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

Fix vendor pull directory creation issue #782

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

Cerebrovinny
Copy link
Collaborator

@Cerebrovinny Cerebrovinny commented Nov 14, 2024

what

Fixed the regression where the vendor command would error if the vendor manifests file path did not exist.

why

Previously, the atmos vendor pull command would fail with a “no such file or directory” error when the vendor manifests file path was missing.

references

Closes #780

Logic design

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for vendor configuration file checks, preventing unnecessary error messages when the file does not exist.
    • Streamlined the logic for processing vendor configuration, enhancing clarity and robustness.

Copy link
Contributor

coderabbitai bot commented Nov 14, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request modify the ReadAndProcessVendorConfigFile function within the internal/exec/vendor_utils.go file. The updates enhance error handling and the logic for processing vendor configuration files. A new variable, foundVendorConfigFile, is introduced to track the vendor configuration file's path, and the logic for checking file existence has been streamlined to return a boolean flag instead of an error when the file is not found.

Changes

File Change Summary
internal/exec/vendor_utils.go Enhanced ReadAndProcessVendorConfigFile by improving error handling and logic for vendor configuration file checks. Added variables foundVendorConfigFile and vendorConfigFileExists, and removed redundant error messages.

Possibly related PRs

Suggested labels

patch

Suggested reviewers

  • osterman
  • aknysh
  • nitrocode

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1b5f112 and 59a9602.

📒 Files selected for processing (1)
  • internal/exec/vendor_utils.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/exec/vendor_utils.go

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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 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

🧹 Outside diff range and nitpick comments (1)
internal/exec/vendor_utils.go (1)

554-557: LGTM! This is a solid fix for the directory creation issue.

The addition of os.MkdirAll before the copy operation is exactly what was needed to resolve the "no such file or directory" error. The error handling is well-structured and provides clear feedback.

A small suggestion to make the code even more robust:

 targetDir := filepath.Dir(targetPath)
-if err := os.MkdirAll(targetDir, 0755); err != nil {
+if err := os.MkdirAll(targetDir, 0o755); err != nil {
   return fmt.Errorf("failed to create target directory '%s': %w", targetDir, err)
 }

Using 0o755 instead of 0755 makes the octal permission more explicit and follows modern Go conventions.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9acca77 and cf24006.

📒 Files selected for processing (1)
  • internal/exec/vendor_utils.go (1 hunks)

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 14, 2024
@osterman
Copy link
Member

osterman commented Nov 14, 2024

@Cerebrovinny I do not think this is the fix based on the description of the problem. Bear in mind we have two types of vendor manifests.

https://atmos.tools/core-concepts/vendor/

The bug report concerns the component manifest file. That means that any logic relating to the vendor manifests file should not inhibit the component manifest from functioning.

To me, it sounds like the regression is that when vendoring a component manifest, it is erroring if the vendor manifests file path does not exist. However, that should not be required. We should instead log to warning that the path does not exist and continue processing.

We should not create the vendor configuration path if it does not exist.

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 15, 2024
@Cerebrovinny
Copy link
Collaborator Author

Cerebrovinny commented Nov 15, 2024

@osterman @aknysh another idea would be start integrating something like this in documentation so the users can consult

@@ -83,7 +83,7 @@ func ExecuteVendorPullCommand(cmd *cobra.Command, args []string) error {

// Check `vendor.yaml`
vendorConfig, vendorConfigExists, foundVendorConfigFile, err := ReadAndProcessVendorConfigFile(cliConfig, cfg.AtmosVendorConfigFileName)
if err != nil {
if vendorConfigExists && err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should log a warning to make it easier to debug

Copy link
Member

Choose a reason for hiding this comment

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

@coderabbitai any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

@osterman, we can add a warning log when the vendor config file does not exist to make debugging easier. This way, we inform the user and allow the process to continue.


🧠 Learnings used
Learnt from: Cerebrovinny
PR: cloudposse/atmos#737
File: internal/exec/vendor_utils.go:131-141
Timestamp: 2024-11-12T05:52:05.088Z
Learning: In the `ReadAndProcessVendorConfigFile` function in `internal/exec/vendor_utils.go`, the existence of the vendor config file is already checked, so additional file existence checks may be unnecessary.

Copy link
Member

Choose a reason for hiding this comment

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

@coderabbitai please make the suggestion

Copy link
Contributor

Choose a reason for hiding this comment

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

@osterman, to implement the warning log, we can modify the ReadAndProcessVendorConfigFile function to log a warning when the vendor config file does not exist and allow the process to continue. Here's how we can adjust the code:

In ReadAndProcessVendorConfigFile, after attempting to locate the vendor config file, check if the file does not exist, log a warning, set vendorConfigFileExists to false, and return without an error:

// After attempting to find the vendor config file
if !vendorConfigFileExists {
    u.LogWarning(cliConfig, fmt.Sprintf("Vendor config file '%s' does not exist. Proceeding without vendor configurations.", vendorConfigFile))
    return vendorConfig, vendorConfigFileExists, "", nil
}

In the calling function ExecuteVendorPullCommand, adjust the error handling condition to remove the check for vendorConfigExists, since the absence of the file is no longer an error:

- if vendorConfigExists && err != nil {
+ if err != nil {
    return err
}

This way, if the vendor config file is not present, a warning will be logged, and the process will continue without interruption.

Let me know if this approach works for you.


🧠 Learnings used
Learnt from: Cerebrovinny
PR: cloudposse/atmos#737
File: internal/exec/vendor_utils.go:131-141
Timestamp: 2024-11-12T05:52:05.088Z
Learning: In the `ReadAndProcessVendorConfigFile` function in `internal/exec/vendor_utils.go`, the existence of the vendor config file is already checked, so additional file existence checks may be unnecessary.

Copy link
Member

Choose a reason for hiding this comment

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

@Cerebrovinny ☝️

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

@osterman osterman added the patch A minor, backward compatible change label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch A minor, backward compatible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Running atmos vendor pull using component.yaml failing
2 participants