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

Bugfixes: low hanging fruit #55

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

Bugfixes: low hanging fruit #55

wants to merge 4 commits into from

Conversation

bohendo
Copy link
Collaborator

@bohendo bohendo commented Jul 26, 2024

This PR targets 3 small, unrelated bugs that were reported recently.

resolves #50 #52 #54

Summary by CodeRabbit

  • Refactor: Improved code consistency in cancel.go and main.go by adjusting indentation and handling of configuration file paths.
  • New Feature: Added a fmt option to the trunk command in the justfile, enhancing user control over formatting.
  • Style: Updated the ANSI color code for white text in log.go for better visibility in console output.

Copy link

github-actions bot commented Jul 26, 2024

Image description CodeRabbit

Walkthrough

This pull request introduces changes to the handling of configuration files in cloudexec, improves console output aesthetics, and extends functionality in the justfile. The alterations span across cancel.go, main.go, clean.go, log.go, and justfile, enhancing usability, error messaging, and code maintainability.

Changes

File(s) Summary
cmd/cloudexec/cancel.go, cmd/cloudexec/main.go Adjusted indentation for consistency and improved handling of configuration file paths. Enhanced error messages for better user experience.
cmd/cloudexec/clean.go Requires review due to unspecified changes.
justfile Added a fmt option to the trunk command, potentially impacting logic and functionality.
pkg/log/log.go Updated ANSI color code for white, affecting the appearance of console output.

🐰 "In the land of code, where the shadows lie,

A rabbit hopped forth, under the cloudless sky.

With each leap and bound, changes were made,

In the realm of configs, where paths are laid.

A touch of color, a dash of fun,

Console outputs now brighter than the sun.

And in the justfile, a new command takes flight,

Celebrating changes, in the soft moonlight." 🌙


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects.

@@ -12,7 +12,7 @@ import (
)

func CleanJob(config config.Config, existingState *state.State, jobID int64, force bool) error {
prefix := fmt.Sprintf("job-%v", jobID)
prefix := fmt.Sprintf("job-%v/", jobID)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Add a / to the end of the deletion prefix so that deleting job-1 doesn't also delete from job-10, etc

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between bfae614 and 1595eb8 commits.
Files selected (5)
  • cmd/cloudexec/cancel.go (1)
  • cmd/cloudexec/clean.go (1)
  • cmd/cloudexec/main.go (4)
  • justfile (1)
  • pkg/log/log.go (1)
Files skipped from review due to trivial changes (1)
  • cmd/cloudexec/cancel.go
Review comments generated (7)
  • Review: 5
  • LGTM: 2

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

@@ -12,7 +12,7 @@ import (
)

func CleanJob(config config.Config, existingState *state.State, jobID int64, force bool) error {
prefix := fmt.Sprintf("job-%v", jobID)
prefix := fmt.Sprintf("job-%v/", jobID)

Choose a reason for hiding this comment

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

Image description CodeRabbit

The change from job-%v to job-%v/ in the prefix string format is significant. This change will affect how objects are listed from S3. If the intention is to list all objects under a specific job directory, this change is correct. However, if the intention was to list objects that start with job-{jobID}, this change could cause unexpected behavior.

- prefix := fmt.Sprintf("job-%v", jobID)
+ prefix := fmt.Sprintf("job-%v/", jobID)

Please ensure that this change aligns with the intended functionality.

@@ -10,7 +10,7 @@ const (
ColorGreen = "\033[32m"
ColorBlue = "\033[34m"
ColorYellow = "\033[33m"
ColorWhite = "\033[37m"
ColorWhite = "\033[97m"

Choose a reason for hiding this comment

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

Image description CodeRabbit

The change from "\033[37m" to "\033[97m" for ColorWhite alters the color code for white. While "\033[37m" represents a standard white, "\033[97m" is a bright white. This might make the white text too bright or unreadable on some terminals with light backgrounds. It would be better to ensure compatibility across different terminal themes.

- 	ColorWhite  = "\033[97m"
+ 	ColorWhite  = "\033[37m"

Comment on lines +8 to 10
trunk: fmt
trunk fmt
trunk check

Choose a reason for hiding this comment

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

Image description CodeRabbit

The change made to the justfile seems to be renaming the trunk command to trunk: fmt. This could potentially break any scripts or processes that rely on the trunk command. If the intention was to add a new command fmt under trunk, it should be done like this:

- trunk: fmt
+ trunk-fmt:

This way, the original trunk command remains intact and a new command trunk-fmt is added.

Comment on lines +17 to +20
Version = "dev"
Commit = "none"
Date = "unknown"
ConfigFilePath = fmt.Sprintf("%s/.config/cloudexec/config.toml", os.Getenv("HOME"))

Choose a reason for hiding this comment

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

Image description CodeRabbit

The removal of LaunchConfigFilePath from the global variables and its addition as a default value for the config flag in the CLI command is a good change. It makes the code more modular and less dependent on global state. However, it's important to note that using os.Getenv("HOME") directly can lead to issues if the environment variable is not set. Consider using os.UserHomeDir() instead which handles more edge cases.

- ConfigFilePath = fmt.Sprintf("%s/.config/cloudexec/config.toml", os.Getenv("HOME"))
+ homeDir, _ := os.UserHomeDir()
+ ConfigFilePath = fmt.Sprintf("%s/.config/cloudexec/config.toml", homeDir)

Comment on lines 112 to 121
launchConfigFilePath := c.String("config")
if _, err := os.Stat(launchConfigFilePath); os.IsNotExist(err) {
// Check if the path to a launch config is provided
if c.Args().Len() < 1 {
return fmt.Errorf("please provide a path to a cloudexec.toml file or create one in the current directory")
return fmt.Errorf("please create cloudexec.toml with 'cloudexec init' or use the '--config' flag to provide a path to your custom launch config file")
}
LaunchConfigFilePath = c.Args().Get(0)
launchConfigFilePath = c.String("config")
}
// Load the launch configuration
lc, err := LoadLaunchConfig(LaunchConfigFilePath)
lc, err := LoadLaunchConfig(launchConfigFilePath)

Choose a reason for hiding this comment

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

Image description CodeRabbit

There seems to be a redundant line at 118 where launchConfigFilePath is assigned the same value again from c.String("config"). This is unnecessary as it doesn't change between lines 112 and 118. You should remove this redundancy.

- launchConfigFilePath = c.String("config")

@@ -10,7 +10,7 @@ const (
ColorGreen = "\033[32m"
ColorBlue = "\033[34m"
ColorYellow = "\033[33m"
ColorWhite = "\033[37m"
ColorWhite = "\033[97m"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the color control code for "bright white" which looks an awful lot like default white tbh, either way: it's brighter and easier to read than the gray.

}
// Load the launch configuration
lc, err := LoadLaunchConfig(LaunchConfigFilePath)
lc, err := LoadLaunchConfig(launchConfigFilePath)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The config flag was defined, mentioned in help text, but was completely ignored. It might surprise you by trying to load a launch config from the first positional arg, but that wouldn't work if other flags are provided first.

This change switches to using the --config flag as you'd expect based on help text.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 1595eb8 and 979c567 commits.
Files selected (1)
  • cmd/cloudexec/main.go (4)
Review comments generated (4)
  • Review: 1
  • LGTM: 3

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines +112 to +117
launchConfigFilePath := c.String("config")
if _, err := os.Stat(launchConfigFilePath); os.IsNotExist(err) {
return fmt.Errorf("please create cloudexec.toml with 'cloudexec init' or use the '--config' flag to provide a path to your custom launch config file")
}
// Load the launch configuration
lc, err := LoadLaunchConfig(LaunchConfigFilePath)
lc, err := LoadLaunchConfig(launchConfigFilePath)

Choose a reason for hiding this comment

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

Image description CodeRabbit

The error handling here could be improved. Currently, if os.Stat fails for a reason other than the file not existing (e.g., insufficient permissions), the error message will still suggest that the file does not exist. It would be better to handle these cases separately.

- if _, err := os.Stat(launchConfigFilePath); os.IsNotExist(err) {
+ if _, err := os.Stat(launchConfigFilePath); err != nil {
+   if os.IsNotExist(err) {
      return fmt.Errorf("please create cloudexec.toml with 'cloudexec init' or use the '--config' flag to provide a path to your custom launch config file")
+   } else {
+     return fmt.Errorf("error checking for cloudexec.toml: %v", err)
+   }
+ }

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.

deleting bucket id deletes all buckets with matching prefix
1 participant