Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ func ResolveProjectDir(logger logger.Logger, cmd *cobra.Command, required bool)
dir = viper.GetString("preferences.project_dir")
if ProjectExists(dir) {
tui.ShowWarning("Using your last used project directory (%s). You should change into the correct directory or use the --dir flag.", dir)
os.Chdir(dir)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Add error handling for the directory change operation.

The os.Chdir(dir) call can fail for various reasons (directory doesn't exist, permission issues, etc.) but the error is not being handled. This could lead to silent failures where the function returns successfully but the working directory change didn't actually occur.

Apply this diff to add proper error handling:

-			os.Chdir(dir)
+			if err := os.Chdir(dir); err != nil {
+				logger.Warn("Failed to change to project directory %s: %v", dir, err)
+				tui.ShowBanner("Directory Change Failed", fmt.Sprintf("Could not change to the project directory %s: %v\n\nPlease navigate to the directory manually or use the --dir flag.", dir, err), false)
+				os.Exit(1)
+			}

Additionally, consider documenting this side effect in the function's documentation since changing the working directory affects the entire process and could have implications for callers.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
os.Chdir(dir)
if err := os.Chdir(dir); err != nil {
logger.Warn("Failed to change to project directory %s: %v", dir, err)
tui.ShowBanner(
"Directory Change Failed",
fmt.Sprintf(
"Could not change to the project directory %s: %v\n\n"+
"Please navigate to the directory manually or use the --dir flag.",
dir,
err,
),
false,
)
os.Exit(1)
}
🤖 Prompt for AI Agents
In internal/project/project.go at line 644, the call to os.Chdir(dir) lacks
error handling, which can cause silent failures if changing the directory fails.
Modify the code to capture the error returned by os.Chdir and handle it
appropriately, such as returning the error or logging it. Also, update the
function's documentation to mention that it changes the working directory,
highlighting this side effect for callers.

return dir
}
tui.ShowBanner("Agentuity Project Not Found", "No Agentuity project file not found in the directory "+abs+"\n\nMake sure you are in an Agentuity project directory or use the --dir flag to specify a project directory.", false)
Expand Down
Loading