Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
error message improvements
Dane Schneiderd01767acc335
diff --git a/app/cli/auth/auth.go b/app/cli/auth/auth.goindex 1e679b3c..fd13da1a 100644--- a/app/cli/auth/auth.go+++ b/app/cli/auth/auth.go@@ -5,6 +5,7 @@ import ("fmt""os""plandex/fs"+ "plandex/term""plandex/types")@@ -46,18 +47,18 @@ func MustResolveAuth(requireOrg bool) {orgs, apiErr := apiClient.ListOrgs()if apiErr != nil {- panic(fmt.Errorf("error listing orgs: %v", apiErr.Msg))+ term.OutputErrorAndExit("Error listing orgs: %v", apiErr.Msg)}orgId, orgName, err := resolveOrgAuth(orgs)if err != nil {- panic(fmt.Errorf("error resolving org: %v", err))+ term.OutputErrorAndExit("Error resolving org: %v", err)}if orgId == "" {// still no org--exit now- os.Exit(1)+ term.OutputErrorAndExit("No org")}Current.OrgId = orgId@@ -66,7 +67,7 @@ func MustResolveAuth(requireOrg bool) {err = writeCurrentAuth()if err != nil {- panic(fmt.Errorf("error writing auth: %v", err))+ term.OutputErrorAndExit("Error writing auth: %v", err)}}@@ -91,8 +92,7 @@ func RefreshInvalidToken() error {host = "Plandex Cloud"}- fmt.Printf("π¨ Account %s not found on %s\n", Current.Email, host)- os.Exit(1)+ term.OutputErrorAndExit("Account %s not found on %s", Current.Email, host)}return nildiff --git a/app/cli/auth/trial.go b/app/cli/auth/trial.goindex 5e5409fa..dd6015ca 100644--- a/app/cli/auth/trial.go+++ b/app/cli/auth/trial.go@@ -2,7 +2,6 @@ package authimport ("fmt"- "os""plandex/term""plandex/types"@@ -23,8 +22,7 @@ func ConvertTrial() error {}if hasAccount {- fmt.Println("π¨ Can't convert a trial into an account that already exists")- os.Exit(1)+ term.OutputErrorAndExit("Can't convert a trial into an account that already exists")}name, err := term.GetUserStringInput("Your name:")diff --git a/app/cli/cmd/apply.go b/app/cli/cmd/apply.goindex 2865f1ec..6fc3156a 100644--- a/app/cli/cmd/apply.go+++ b/app/cli/cmd/apply.go@@ -4,6 +4,7 @@ import ("fmt""plandex/auth""plandex/lib"+ "plandex/term""github.com/spf13/cobra")@@ -35,7 +36,7 @@ func apply(cmd *cobra.Command, args []string) {err := lib.ApplyPlan(lib.CurrentPlanId, lib.CurrentBranch, autoConfirm)if err != nil {- fmt.Println("Error applying plan:", err)+ term.OutputErrorAndExit("Error applying plan: %v", err)return}}diff --git a/app/cli/cmd/branches.go b/app/cli/cmd/branches.goindex 086ff8bd..bd3b9b50 100644--- a/app/cli/cmd/branches.go+++ b/app/cli/cmd/branches.go@@ -38,7 +38,7 @@ func branches(cmd *cobra.Command, args []string) {branches, apiErr := api.Client.ListBranches(lib.CurrentPlanId)if apiErr != nil {- fmt.Println("Error getting branches:", apiErr)+ term.OutputErrorAndExit("Error getting branches: %v", apiErr)return}diff --git a/app/cli/cmd/build.go b/app/cli/cmd/build.goindex 3ec7fd2b..86de465d 100644--- a/app/cli/cmd/build.go+++ b/app/cli/cmd/build.go@@ -30,15 +30,14 @@ func init() {func build(cmd *cobra.Command, args []string) {if os.Getenv("OPENAI_API_KEY") == "" {- term.OutputNoApiKeyMsg()- os.Exit(1)+ term.OutputNoApiKeyMsgAndExit()}auth.MustResolveAuthWithOrg()lib.MustResolveProject()if lib.CurrentPlanId == "" {- fmt.Fprintln(os.Stderr, "No current plan")+ fmt.Println("π€·ββοΈ No current plan")return}@@ -51,8 +50,7 @@ func build(cmd *cobra.Command, args []string) {}, buildBg)if err != nil {- fmt.Fprintln(os.Stderr, err)- return+ term.OutputErrorAndExit("Error building plan: %v", err)}if !didBuild {diff --git a/app/cli/cmd/cd.go b/app/cli/cmd/cd.goindex 2d4b3e4e..1653e9b5 100644--- a/app/cli/cmd/cd.go+++ b/app/cli/cmd/cd.go@@ -2,7 +2,6 @@ package cmdimport ("fmt"- "os""plandex/api""plandex/auth""plandex/lib"@@ -42,8 +41,7 @@ func cd(cmd *cobra.Command, args []string) {plans, apiErr := api.Client.ListPlans([]string{lib.CurrentProjectId})if apiErr != nil {- fmt.Fprintln(os.Stderr, "Error getting plans:", apiErr.Msg)- os.Exit(1)+ term.OutputErrorAndExit("Error getting plans: %v", apiErr)}if len(plans) == 0 {@@ -63,8 +61,7 @@ func cd(cmd *cobra.Command, args []string) {selected, err := term.SelectFromList("Select a plan", opts)if err != nil {- fmt.Fprintln(os.Stderr, "Error selecting plan:", err)- return+ term.OutputErrorAndExit("Error selecting plan: %v", err)}for _, p := range plans {@@ -81,8 +78,7 @@ func cd(cmd *cobra.Command, args []string) {if idx > 0 && idx <= len(plans) {plan = plans[idx-1]} else {- fmt.Fprintln(os.Stderr, "Error: index out of range")- os.Exit(1)+ term.OutputErrorAndExit("Plan index out of range")}} else {for _, p := range plans {@@ -95,14 +91,12 @@ func cd(cmd *cobra.Command, args []string) {}if plan == nil {- fmt.Fprintln(os.Stderr, "π¨ Plan not found")- os.Exit(1)+ term.OutputErrorAndExit("Plan not found")}err := lib.WriteCurrentPlan(plan.Id)if err != nil {- fmt.Fprintln(os.Stderr, "Error setting current plan:", err)- os.Exit(1)+ term.OutputErrorAndExit("Error setting current plan: %v", err)}// reload current plan, which will also handle setting the right branch@@ -115,7 +109,7 @@ func cd(cmd *cobra.Command, args []string) {// give the SetProjectPlan request some time to be sent before exitingtime.Sleep(50 * time.Millisecond)- fmt.Fprintln(os.Stderr, "β Changed current plan to "+color.New(color.FgGreen, color.Bold).Sprint(plan.Name))+ fmt.Println("β Changed current plan to " + color.New(color.FgGreen, color.Bold).Sprint(plan.Name))fmt.Println()term.PrintCmds("", "current")diff --git a/app/cli/cmd/changes.go b/app/cli/cmd/changes.goindex e78f5ae8..58e6d584 100644--- a/app/cli/cmd/changes.go+++ b/app/cli/cmd/changes.go@@ -2,7 +2,6 @@ package cmdimport ("fmt"- "os""plandex/api""plandex/auth""plandex/changes_tui"@@ -35,17 +34,15 @@ func changes(cmd *cobra.Command, args []string) {if apiErr != nil {term.StopSpinner()- fmt.Fprintf(os.Stderr, "Error getting current plan state: %s\n", apiErr.Msg)- return+ term.OutputErrorAndExit("Error getting current plan state: %s", apiErr.Msg)}if currentPlanState.HasPendingBuilds() {plansRunningRes, apiErr := api.Client.ListPlansRunning([]string{lib.CurrentProjectId}, false)if apiErr != nil {- // return fmt.Errorf("error getting running plans: %s", apiErr.Msg)term.StopSpinner()- fmt.Fprintf(os.Stderr, "Error getting running plans: %s\n", apiErr.Msg)+ term.OutputErrorAndExit("Error getting running plans: %s", apiErr.Msg)}viewIncomplete := false@@ -57,8 +54,7 @@ func changes(cmd *cobra.Command, args []string) {res, err := term.ConfirmYesNo("View potentially incomplete changes anyway?")if err != nil {- fmt.Fprintf(os.Stderr, "Error getting confirmation user input: %s\n", err)- return+ term.OutputErrorAndExit("Error getting confirmation user input: %v", err)}if res {@@ -86,8 +82,7 @@ func changes(cmd *cobra.Command, args []string) {}, false)if err != nil {- fmt.Fprintf(os.Stderr, "Error building plan: %v\n", err)- return+ term.OutputErrorAndExit("Error building plan: %v\n", err)}if !didBuild {@@ -104,7 +99,7 @@ func changes(cmd *cobra.Command, args []string) {err := changes_tui.StartChangesUI()if err != nil {- fmt.Fprintf(os.Stderr, "Error starting changes UI: %v\n", err)+ term.OutputErrorAndExit("Error starting changes UI: %v\n", err)}}diff --git a/app/cli/cmd/checkout.go b/app/cli/cmd/checkout.goindex 94c670f7..8f535b48 100644--- a/app/cli/cmd/checkout.go+++ b/app/cli/cmd/checkout.go@@ -2,7 +2,6 @@ package cmdimport ("fmt"- "os""plandex/api""plandex/auth""plandex/lib"@@ -51,7 +50,7 @@ func checkout(cmd *cobra.Command, args []string) {branches, apiErr := api.Client.ListBranches(lib.CurrentPlanId)if apiErr != nil {- fmt.Println("Error getting branches:", apiErr)+ term.OutputErrorAndExit("Error getting branches: %v", apiErr)return}@@ -62,8 +61,7 @@ func checkout(cmd *cobra.Command, args []string) {if idx > 0 && idx <= len(branches) {branchName = branches[idx-1].Name} else {- fmt.Fprintf(os.Stderr, "π¨ Branch %d not found\n", idx)- os.Exit(1)+ term.OutputErrorAndExit("Branch %d not found", idx)}} else {for _, b := range branches {@@ -79,7 +77,7 @@ func checkout(cmd *cobra.Command, args []string) {res, err := term.ConfirmYesNo("Create it now?")if err != nil {- fmt.Println("Error getting user input:", err)+ term.OutputErrorAndExit("Error getting user input: %v", err)}if res {@@ -102,14 +100,14 @@ func checkout(cmd *cobra.Command, args []string) {selected, err := term.SelectFromList("Select a branch", opts)if err != nil {- fmt.Println("Error selecting branch:", err)+ term.OutputErrorAndExit("Error selecting branch: %v", err)return}if selected == OptCreateNewBranch {branchName, err = term.GetUserStringInput("Branch name")if err != nil {- fmt.Println("Error getting branch name:", err)+ term.OutputErrorAndExit("Error getting branch name: %v", err)return}willCreate = true@@ -119,8 +117,7 @@ func checkout(cmd *cobra.Command, args []string) {}if branchName == "" {- fmt.Fprintln(os.Stderr, "π¨ Branch not found")- os.Exit(1)+ term.OutputErrorAndExit("Branch not found")}if willCreate {@@ -129,7 +126,7 @@ func checkout(cmd *cobra.Command, args []string) {if err != nil {term.StopSpinner()- fmt.Println("Error creating branch:", err)+ term.OutputErrorAndExit("Error creating branch: %v", err)return}@@ -140,7 +137,7 @@ func checkout(cmd *cobra.Command, args []string) {err := lib.WriteCurrentBranch(branchName)if err != nil {- fmt.Println("Error setting current branch:", err)+ term.OutputErrorAndExit("Error setting current branch: %v", err)return}diff --git a/app/cli/cmd/clear.go b/app/cli/cmd/clear.goindex 12f2842d..2bef38a8 100644--- a/app/cli/cmd/clear.go+++ b/app/cli/cmd/clear.go@@ -2,10 +2,10 @@ package cmdimport ("fmt"- "os""plandex/api""plandex/auth""plandex/lib"+ "plandex/term""github.com/plandex/plandex/shared""github.com/spf13/cobra"@@ -23,15 +23,14 @@ func clearAllContext(cmd *cobra.Command, args []string) {lib.MustResolveProject()if lib.CurrentPlanId == "" {- fmt.Fprintln(os.Stderr, "No current plan")+ fmt.Println("π€·ββοΈ No current plan")return}contexts, err := api.Client.ListContext(lib.CurrentPlanId, lib.CurrentBranch)if err != nil {- fmt.Fprintln(os.Stderr, "Error retrieving context:", err)- return+ term.OutputErrorAndExit("Error retrieving context: %v", err)}deleteIds := map[string]bool{}@@ -46,8 +45,7 @@ func clearAllContext(cmd *cobra.Command, args []string) {})if err != nil {- fmt.Fprintln(os.Stderr, "Error deleting context:", err)- return+ term.OutputErrorAndExit("Error deleting context: %v", err)}fmt.Println("β " + res.Msg)diff --git a/app/cli/cmd/connect.go b/app/cli/cmd/connect.goindex 6fb60727..1caf3ba9 100644--- a/app/cli/cmd/connect.go+++ b/app/cli/cmd/connect.go@@ -2,7 +2,6 @@ package cmdimport ("fmt"- "log""os""plandex/api""plandex/auth"@@ -33,7 +32,7 @@ func connect(cmd *cobra.Command, args []string) {lib.MustResolveProject()if lib.CurrentPlanId == "" {- fmt.Fprintln(os.Stderr, "No current plan")+ fmt.Println("π€·ββοΈ No current plan")return}@@ -46,16 +45,14 @@ func connect(cmd *cobra.Command, args []string) {apiErr := api.Client.ConnectPlan(planId, branch, stream.OnStreamPlan)if apiErr != nil {- fmt.Fprintln(os.Stderr, "Error connecting to stream:", apiErr.Msg)- return+ term.OutputErrorAndExit("Error connecting to stream: %v", apiErr)}go func() {err := streamtui.StartStreamUI("", false)if err != nil {- log.Printf("Error starting stream UI: %v\n", err)- os.Exit(1)+ term.OutputErrorAndExit("Error starting stream UI", err)}fmt.Println()diff --git a/app/cli/cmd/continue.go b/app/cli/cmd/continue.goindex 812b7291..9afb0221 100644--- a/app/cli/cmd/continue.go+++ b/app/cli/cmd/continue.go@@ -29,15 +29,14 @@ func init() {func doContinue(cmd *cobra.Command, args []string) {if os.Getenv("OPENAI_API_KEY") == "" {- term.OutputNoApiKeyMsg()- os.Exit(1)+ term.OutputNoApiKeyMsgAndExit()}auth.MustResolveAuthWithOrg()lib.MustResolveProject()if lib.CurrentPlanId == "" {- fmt.Fprintln(os.Stderr, "No current plan")+ fmt.Println("π€·ββοΈ No current plan")return}diff --git a/app/cli/cmd/convo.go b/app/cli/cmd/convo.goindex e88be873..11362606 100644--- a/app/cli/cmd/convo.go+++ b/app/cli/cmd/convo.go@@ -2,7 +2,6 @@ package cmdimport ("fmt"- "os""plandex/api""plandex/auth""plandex/lib"@@ -33,8 +32,7 @@ func convo(cmd *cobra.Command, args []string) {conversation, apiErr := api.Client.ListConvo(lib.CurrentPlanId, lib.CurrentBranch)if apiErr != nil {- fmt.Fprintln(os.Stderr, "Error loading conversation:", apiErr.Msg)- return+ term.OutputErrorAndExit("Error loading conversation: %v", apiErr.Msg)}if len(conversation) == 0 {@@ -74,8 +72,7 @@ func convo(cmd *cobra.Command, args []string) {md, err := term.GetMarkdown(header + "\n" + msg.Message + "\n\n")if err != nil {- fmt.Fprintln(os.Stderr, "Error creating markdown representation:", err)- return+ term.OutputErrorAndExit("Error creating markdown representation: %v", err)}convo += mddiff --git a/app/cli/cmd/current.go b/app/cli/cmd/current.goindex d1767f88..552994fc 100644--- a/app/cli/cmd/current.go+++ b/app/cli/cmd/current.go@@ -38,7 +38,7 @@ func current(cmd *cobra.Command, args []string) {plan, err := api.Client.GetPlan(lib.CurrentPlanId)if err != nil {- fmt.Println("Error getting plan:", err)+ term.OutputErrorAndExit("Error getting plan: %v", err)return}@@ -49,8 +49,7 @@ func current(cmd *cobra.Command, args []string) {})if err != nil {- fmt.Fprintln(os.Stderr, "Error getting current branches:", err)- return+ term.OutputErrorAndExit("Error getting current branches: %v", err)}table := tablewriter.NewWriter(os.Stdout)diff --git a/app/cli/cmd/delete_branch.go b/app/cli/cmd/delete_branch.goindex 76c18210..397e88aa 100644--- a/app/cli/cmd/delete_branch.go+++ b/app/cli/cmd/delete_branch.go@@ -2,7 +2,6 @@ package cmdimport ("fmt"- "os""plandex/api""plandex/auth""plandex/lib"@@ -10,6 +9,7 @@ import ("strconv""strings"+ "github.com/fatih/color""github.com/spf13/cobra")@@ -49,7 +49,7 @@ func deleteBranch(cmd *cobra.Command, args []string) {branches, apiErr := api.Client.ListBranches(lib.CurrentPlanId)if apiErr != nil {- fmt.Println("Error getting branches:", apiErr)+ term.OutputErrorAndExit("Error getting branches: %v", apiErr)return}@@ -70,7 +70,7 @@ func deleteBranch(cmd *cobra.Command, args []string) {sel, err := term.SelectFromList("Select a branch to delete", opts)if err != nil {- fmt.Println("Error selecting branch:", err)+ term.OutputErrorAndExit("Error selecting branch: %v", err)return}@@ -84,8 +84,7 @@ func deleteBranch(cmd *cobra.Command, args []string) {if idx > 0 && idx <= len(branches) {branch = branches[idx-1].Name} else {- fmt.Fprintln(os.Stderr, "Error: index out of range")- os.Exit(1)+ term.OutputErrorAndExit("Branch index out of range")}} else {for _, b := range branches {@@ -96,8 +95,7 @@ func deleteBranch(cmd *cobra.Command, args []string) {}if branch == "" {- fmt.Fprintln(os.Stderr, "Error: branch not found")- os.Exit(1)+ term.OutputErrorAndExit("Branch not found")}}@@ -110,18 +108,18 @@ func deleteBranch(cmd *cobra.Command, args []string) {}if !found {- fmt.Printf("π€·ββοΈ Branch '%s' does not exist\n", branch)+ fmt.Printf("π€·ββοΈ Branch %s does not exist\n", color.New(color.Bold, color.FgHiCyan).Sprint(branch))return}apiErr = api.Client.DeleteBranch(lib.CurrentPlanId, branch)if apiErr != nil {- fmt.Println("Error deleting branch:", apiErr)+ term.OutputErrorAndExit("Error deleting branch: %v", apiErr)return}- fmt.Printf("β Deleted branch '%s'\n", branch)+ fmt.Printf("β Deleted branch %s\n", color.New(color.Bold, color.FgHiCyan).Sprint(branch))fmt.Println()term.PrintCmds("", "branches")diff --git a/app/cli/cmd/delete_plan.go b/app/cli/cmd/delete_plan.goindex 34887f7f..86d7f75c 100644--- a/app/cli/cmd/delete_plan.go+++ b/app/cli/cmd/delete_plan.go@@ -2,7 +2,6 @@ package cmdimport ("fmt"- "os""strconv""strings"@@ -46,8 +45,7 @@ func del(cmd *cobra.Command, args []string) {nameOrIdx = strings.TrimSpace(args[0])if all {- fmt.Fprintln(os.Stderr, "π¨ Can't use both --all and a plan name or index")- return+ term.OutputErrorAndExit("Can't use both --all and a plan name or index")}}var plan *shared.Plan@@ -55,8 +53,7 @@ func del(cmd *cobra.Command, args []string) {plans, apiErr := api.Client.ListPlans([]string{lib.CurrentProjectId})if apiErr != nil {- fmt.Fprintln(os.Stderr, "Error getting plans:", apiErr.Msg)- os.Exit(1)+ term.OutputErrorAndExit("Error getting plans: %v", apiErr)}if len(plans) == 0 {@@ -76,8 +73,7 @@ func del(cmd *cobra.Command, args []string) {selected, err := term.SelectFromList("Select a plan", opts)if err != nil {- fmt.Fprintln(os.Stderr, "Error selecting plan:", err)- return+ term.OutputErrorAndExit("Error selecting plan: %v", err)}for _, p := range plans {@@ -95,8 +91,7 @@ func del(cmd *cobra.Command, args []string) {if idx > 0 && idx <= len(plans) {plan = plans[idx-1]} else {- fmt.Fprintln(os.Stderr, "Error: index out of range")- os.Exit(1)+ term.OutputErrorAndExit("Plan index out of range")}} else {for _, p := range plans {@@ -109,34 +104,30 @@ func del(cmd *cobra.Command, args []string) {}if plan == nil {- fmt.Fprintln(os.Stderr, "π¨ Plan not found")- os.Exit(1)+ term.OutputErrorAndExit("Plan not found")}apiErr = api.Client.DeletePlan(plan.Id)if apiErr != nil {- fmt.Fprintln(os.Stderr, "Error deleting plan:", apiErr.Msg)- return+ term.OutputErrorAndExit("Error deleting plan: %s", apiErr.Msg)}if lib.CurrentPlanId == plan.Id {err := lib.ClearCurrentPlan()if err != nil {- fmt.Fprintln(os.Stderr, "Error clearing current plan:", err)- return+ term.OutputErrorAndExit("Error clearing current plan: %v", err)}}- fmt.Printf("β Deleted plan %s\n", color.New(color.Bold).Sprint(plan.Name))+ fmt.Printf("β Deleted plan %s\n", color.New(color.Bold, color.FgHiCyan).Sprint(plan.Name))}func delAll() {err := api.Client.DeleteAllPlans(lib.CurrentProjectId)if err != nil {- fmt.Fprintln(os.Stderr, "Error deleting all plans:", err)- return+ term.OutputErrorAndExit("Error deleting all plans: %v", err)}- fmt.Fprintln(os.Stderr, "β Deleted all plans")+ fmt.Println("β Deleted all plans")}diff --git a/app/cli/cmd/load.go b/app/cli/cmd/load.goindex d8b65408..175fe36a 100644--- a/app/cli/cmd/load.go+++ b/app/cli/cmd/load.go@@ -2,7 +2,6 @@ package cmdimport ("fmt"- "os""plandex/auth""plandex/lib""plandex/term"@@ -39,7 +38,7 @@ func contextLoad(cmd *cobra.Command, args []string) {lib.MustResolveProject()if lib.CurrentPlanId == "" {- fmt.Fprintln(os.Stderr, "No current plan")+ fmt.Println("π€·ββοΈ No current plan")return}diff --git a/app/cli/cmd/log.go b/app/cli/cmd/log.goindex 980d3e50..e6daafb9 100644--- a/app/cli/cmd/log.go+++ b/app/cli/cmd/log.go@@ -38,15 +38,13 @@ func runLog(cmd *cobra.Command, args []string) {res, apiErr := api.Client.ListLogs(lib.CurrentPlanId, lib.CurrentBranch)if apiErr != nil {- fmt.Printf("Error getting logs: %v\n", apiErr)- return+ term.OutputErrorAndExit("Error getting logs: %v", apiErr)}withLocalTimestamps, err := convertTimestampsToLocal(res.Body)if err != nil {- fmt.Printf("Error converting timestamps: %v\n", err)- return+ term.OutputErrorAndExit("Error converting timestamps: %v", err)}term.PageOutput(withLocalTimestamps)diff --git a/app/cli/cmd/ls.go b/app/cli/cmd/ls.goindex dda82118..3bd18858 100644--- a/app/cli/cmd/ls.go+++ b/app/cli/cmd/ls.go@@ -29,8 +29,7 @@ func listContext(cmd *cobra.Command, args []string) {contexts, err := api.Client.ListContext(lib.CurrentPlanId, lib.CurrentBranch)if err != nil {- color.New(color.FgRed).Fprintln(os.Stderr, "Error listing context:", err)- os.Exit(1)+ term.OutputErrorAndExit("Error listing context: %v", err)}totalTokens := 0diff --git a/app/cli/cmd/models.go b/app/cli/cmd/models.goindex 3ee2c890..887d98fd 100644--- a/app/cli/cmd/models.go+++ b/app/cli/cmd/models.go@@ -32,7 +32,7 @@ func models(cmd *cobra.Command, args []string) {settings, err := api.Client.GetSettings(lib.CurrentPlanId, lib.CurrentBranch)if err != nil {- fmt.Println("Error getting settings:", err)+ term.OutputErrorAndExit("Error getting settings: %v", err)return}diff --git a/app/cli/cmd/new.go b/app/cli/cmd/new.goindex 7830b522..036f3958 100644--- a/app/cli/cmd/new.go+++ b/app/cli/cmd/new.go@@ -44,30 +44,26 @@ func new(cmd *cobra.Command, args []string) {res, err := term.ConfirmYesNo("Upgrade trial now?")if err != nil {- fmt.Fprintln(os.Stderr, "Error prompting upgrade trial:", err)- return+ term.OutputErrorAndExit("Error prompting upgrade trial: %v", err)}if res {err := auth.ConvertTrial()if err != nil {- fmt.Fprintln(os.Stderr, "Error converting trial:", err)- return+ term.OutputErrorAndExit("Error converting trial: %v", err)}}return}- fmt.Fprintln(os.Stderr, "Error creating plan:", apiErr.Msg)- return+ term.OutputErrorAndExit("Error creating plan: %v", apiErr.Msg)}err := lib.WriteCurrentPlan(res.Id)if err != nil {- fmt.Fprintln(os.Stderr, "Error setting current plan:", err)- return+ term.OutputErrorAndExit("Error setting current plan: %v", err)}if name == "" {diff --git a/app/cli/cmd/plans.go b/app/cli/cmd/plans.goindex 90b6a483..97233e33 100644--- a/app/cli/cmd/plans.go+++ b/app/cli/cmd/plans.go@@ -82,8 +82,7 @@ func plans(cmd *cobra.Command, args []string) {for i := 0; i < 2; i++ {err := <-errChif err != nil {- fmt.Fprintln(os.Stderr, err)- return+ term.OutputErrorAndExit("%v", err)}}@@ -110,8 +109,7 @@ func plans(cmd *cobra.Command, args []string) {plans, apiErr := api.Client.ListPlans(projectIds)if apiErr != nil {- fmt.Fprintln(os.Stderr, "Error getting plans:", apiErr)- return+ term.OutputErrorAndExit("Error getting plans: %v", apiErr)}log.Println("listed")@@ -145,8 +143,7 @@ func plans(cmd *cobra.Command, args []string) {currentBranchNamesByPlanId, err := lib.GetCurrentBranchNamesByPlanId(currentProjectPlanIds)if err != nil {- fmt.Fprintln(os.Stderr, "Error getting current branches:", err)- return+ term.OutputErrorAndExit("Error getting current branches: %v", err)}currentBranchesByPlanId, apiErr := api.Client.GetCurrentBranchByPlanId(lib.CurrentProjectId, shared.GetCurrentBranchByPlanIdRequest{@@ -154,8 +151,7 @@ func plans(cmd *cobra.Command, args []string) {})if apiErr != nil {- fmt.Fprintln(os.Stderr, "Error getting current branches:", apiErr)- return+ term.OutputErrorAndExit("Error getting current branches: %v", apiErr)}table := tablewriter.NewWriter(os.Stdout)@@ -284,8 +280,7 @@ func plans(cmd *cobra.Command, args []string) {rel, err := filepath.Rel(fs.HomeDir, p[0])if err != nil {- fmt.Fprintln(os.Stderr, "Error getting relative path:", err)- return+ term.OutputErrorAndExit("Error getting relative path: %v", err)}addPathToTreeFn(parentTree, "", rel, p[1], true)@@ -302,8 +297,7 @@ func plans(cmd *cobra.Command, args []string) {rel, err := filepath.Rel(fs.Cwd, p[0])if err != nil {- fmt.Fprintln(os.Stderr, "Error getting relative path:", err)- return+ term.OutputErrorAndExit("Error getting relative path: %v", err)}addPathToTreeFn(childTree, "", rel, p[1], false)diff --git a/app/cli/cmd/ps.go b/app/cli/cmd/ps.goindex 333429ae..e618d334 100644--- a/app/cli/cmd/ps.go+++ b/app/cli/cmd/ps.go@@ -36,7 +36,7 @@ func ps(cmd *cobra.Command, args []string) {res, apiErr := api.Client.ListPlansRunning([]string{lib.CurrentProjectId}, true)if apiErr != nil {- fmt.Println("Error getting running plans:", apiErr)+ term.OutputErrorAndExit("Error getting running plans: %v", apiErr)return}diff --git a/app/cli/cmd/rewind.go b/app/cli/cmd/rewind.goindex 13f23c82..9b0936bc 100644--- a/app/cli/cmd/rewind.go+++ b/app/cli/cmd/rewind.go@@ -2,7 +2,6 @@ package cmdimport ("fmt"- "os""plandex/api""plandex/auth""plandex/lib"@@ -36,7 +35,7 @@ func rewind(cmd *cobra.Command, args []string) {lib.MustResolveProject()if lib.CurrentPlanId == "" {- fmt.Fprintln(os.Stderr, "No current plan")+ fmt.Println("π€·ββοΈ No current plan")return}@@ -50,8 +49,7 @@ func rewind(cmd *cobra.Command, args []string) {logsRes, apiErr := api.Client.ListLogs(lib.CurrentPlanId, lib.CurrentBranch)if apiErr != nil {- fmt.Printf("Error getting logs: %v\n", apiErr)- return+ term.OutputErrorAndExit("Error getting logs: %v", apiErr)}var targetSha string@@ -76,8 +74,7 @@ func rewind(cmd *cobra.Command, args []string) {steps = 1targetSha = logsRes.Shas[1]} else {- fmt.Fprintln(os.Stderr, "Invalid steps or sha. Steps must be a positive integer, and sha must be a valid commit hash.")- os.Exit(1)+ term.OutputErrorAndExit("Invalid steps or sha. Steps must be a positive integer, and sha must be a valid commit hash.")}// log.Println("Rewinding to", targetSha)@@ -86,8 +83,7 @@ func rewind(cmd *cobra.Command, args []string) {_, apiErr = api.Client.RewindPlan(lib.CurrentPlanId, lib.CurrentBranch, shared.RewindPlanRequest{Sha: targetSha})if apiErr != nil {- fmt.Fprintf(os.Stderr, "Error rewinding plan: %v\n", apiErr)- return+ term.OutputErrorAndExit("Error rewinding plan: %v", apiErr)}var msg stringdiff --git a/app/cli/cmd/rm.go b/app/cli/cmd/rm.goindex e69ee421..189f7140 100644--- a/app/cli/cmd/rm.go+++ b/app/cli/cmd/rm.go@@ -2,11 +2,11 @@ package cmdimport ("fmt"- "os""path/filepath""plandex/api""plandex/auth""plandex/lib"+ "plandex/term""github.com/plandex/plandex/shared""github.com/spf13/cobra"@@ -26,15 +26,14 @@ func contextRm(cmd *cobra.Command, args []string) {lib.MustResolveProject()if lib.CurrentPlanId == "" {- fmt.Fprintln(os.Stderr, "No current plan")+ fmt.Println("π€·ββοΈ No current plan")return}contexts, err := api.Client.ListContext(lib.CurrentPlanId, lib.CurrentBranch)if err != nil {- fmt.Fprintln(os.Stderr, "Error retrieving context:", err)- return+ term.OutputErrorAndExit("Error retrieving context: %v", err)}deleteIds := map[string]bool{}@@ -48,8 +47,7 @@ func contextRm(cmd *cobra.Command, args []string) {// Check if id is a glob patternmatched, err := filepath.Match(id, context.FilePath)if err != nil {- fmt.Fprintln(os.Stderr, "Error matching glob pattern:", err)- return+ term.OutputErrorAndExit("Error matching glob pattern: %v", err)}if matched {deleteIds[context.Id] = true@@ -65,8 +63,7 @@ func contextRm(cmd *cobra.Command, args []string) {})if err != nil {- fmt.Fprintln(os.Stderr, "Error deleting context:", err)- return+ term.OutputErrorAndExit("Error deleting context: %v", err)}fmt.Println("β " + res.Msg)diff --git a/app/cli/cmd/root.go b/app/cli/cmd/root.goindex 9abbbd8d..1fb20c0b 100644--- a/app/cli/cmd/root.go+++ b/app/cli/cmd/root.go@@ -1,8 +1,7 @@package cmdimport (- "fmt"- "os"+ "plandex/term""github.com/spf13/cobra")@@ -20,8 +19,7 @@ var RootCmd = &cobra.Command{// This is called by main.main(). It only needs to happen once to the rootCmd.func Execute() {if err := RootCmd.Execute(); err != nil {- fmt.Println(err)- os.Exit(1)+ term.OutputErrorAndExit("Error executing root command: %v", err)}}diff --git a/app/cli/cmd/set_model.go b/app/cli/cmd/set_model.goindex 3ac9963e..ac481608 100644--- a/app/cli/cmd/set_model.go+++ b/app/cli/cmd/set_model.go@@ -33,21 +33,21 @@ func modelsSet(cmd *cobra.Command, args []string) {originalSettings, apiErr := api.Client.GetSettings(lib.CurrentPlanId, lib.CurrentBranch)if apiErr != nil {- fmt.Println("Error getting current settings:", apiErr)+ term.OutputErrorAndExit("Error getting current settings: %v", apiErr)return}// Marshal and unmarshal to make a deep copy of the settingsjsonBytes, err := json.Marshal(originalSettings)if err != nil {- fmt.Println("Error marshalling settings:", err)+ term.OutputErrorAndExit("Error marshalling settings: %v", err)return}var settings *shared.PlanSettingserr = json.Unmarshal(jsonBytes, &settings)if err != nil {- fmt.Println("Error unmarshalling settings:", err)+ term.OutputErrorAndExit("Error unmarshalling settings: %v", err)return}@@ -97,7 +97,7 @@ func modelsSet(cmd *cobra.Command, args []string) {return}- fmt.Println("Error selecting setting or role:", err)+ term.OutputErrorAndExit("Error selecting setting or role: %v", err)return}@@ -141,7 +141,7 @@ func modelsSet(cmd *cobra.Command, args []string) {return}- fmt.Println("Error getting value:", err)+ term.OutputErrorAndExit("Error getting value: %v", err)return}}@@ -206,7 +206,7 @@ func modelsSet(cmd *cobra.Command, args []string) {return}- fmt.Println("Error selecting property:", err)+ term.OutputErrorAndExit("Error selecting property: %v", err)return}@@ -225,7 +225,7 @@ func modelsSet(cmd *cobra.Command, args []string) {return}- fmt.Println("Error selecting model:", err)+ term.OutputErrorAndExit("Error selecting model: %v", err)return}@@ -259,7 +259,7 @@ func modelsSet(cmd *cobra.Command, args []string) {return}- fmt.Println("Error getting value:", err)+ term.OutputErrorAndExit("Error getting value: %v", err)return}}@@ -361,7 +361,7 @@ func modelsSet(cmd *cobra.Command, args []string) {Settings: settings,})if apiErr != nil {- fmt.Println("Error updating settings:", apiErr)+ term.OutputErrorAndExit("Error updating settings: %v", apiErr)return}diff --git a/app/cli/cmd/stop.go b/app/cli/cmd/stop.goindex bf9de45a..21cc4813 100644--- a/app/cli/cmd/stop.go+++ b/app/cli/cmd/stop.go@@ -2,7 +2,6 @@ package cmdimport ("fmt"- "os""plandex/api""plandex/auth""plandex/lib"@@ -28,7 +27,7 @@ func stop(cmd *cobra.Command, args []string) {lib.MustResolveProject()if lib.CurrentPlanId == "" {- fmt.Fprintln(os.Stderr, "No current plan")+ fmt.Println("π€·ββοΈ No current plan")return}@@ -41,8 +40,7 @@ func stop(cmd *cobra.Command, args []string) {apiErr := api.Client.StopPlan(planId, branch)if apiErr != nil {- fmt.Fprintln(os.Stderr, "Error stopping stream:", apiErr.Msg)- return+ term.OutputErrorAndExit("Error stopping stream: %v", apiErr.Msg)}fmt.Println("β Plan stream stopped")diff --git a/app/cli/cmd/tell.go b/app/cli/cmd/tell.goindex 09e560b5..ae187092 100644--- a/app/cli/cmd/tell.go+++ b/app/cli/cmd/tell.go@@ -44,15 +44,14 @@ func init() {func doTell(cmd *cobra.Command, args []string) {if os.Getenv("OPENAI_API_KEY") == "" {- term.OutputNoApiKeyMsg()- os.Exit(1)+ term.OutputNoApiKeyMsgAndExit()}auth.MustResolveAuthWithOrg()lib.MustResolveProject()if lib.CurrentPlanId == "" {- fmt.Fprintln(os.Stderr, "No current plan")+ fmt.Println("π€·ββοΈ No current plan")return}@@ -63,8 +62,7 @@ func doTell(cmd *cobra.Command, args []string) {} else if tellPromptFile != "" {bytes, err := os.ReadFile(tellPromptFile)if err != nil {- fmt.Fprintln(os.Stderr, "Error reading prompt file:", err)- return+ term.OutputErrorAndExit("Error reading prompt file: %v", err)}prompt = string(bytes)} else {@@ -72,7 +70,7 @@ func doTell(cmd *cobra.Command, args []string) {}if prompt == "" {- fmt.Fprintln(os.Stderr, "π€·ββοΈ No prompt to send")+ fmt.Println("π€·ββοΈ No prompt to send")return}@@ -113,16 +111,14 @@ func getEditorPrompt() string {tempFile, err := os.CreateTemp(os.TempDir(), "plandex_prompt_*")if err != nil {- fmt.Fprintln(os.Stderr, "Failed to create temporary file:", err)- os.Exit(1)+ term.OutputErrorAndExit("Failed to create temporary file: %v", err)}instructions := getEditorInstructions(editor)filename := tempFile.Name()err = os.WriteFile(filename, []byte(instructions), 0644)if err != nil {- fmt.Fprintln(os.Stderr, "Failed to write instructions to temporary file:", err)- os.Exit(1)+ term.OutputErrorAndExit("Failed to write instructions to temporary file: %v", err)}editorCmd := prepareEditorCommand(editor, filename)@@ -131,22 +127,19 @@ func getEditorPrompt() string {editorCmd.Stderr = os.Stderrerr = editorCmd.Run()if err != nil {- fmt.Fprintln(os.Stderr, "Error opening editor:", err)- os.Exit(1)+ term.OutputErrorAndExit("Error opening editor: %v", err)}bytes, err := os.ReadFile(tempFile.Name())if err != nil {- fmt.Fprintln(os.Stderr, "Error reading temporary file:", err)- os.Exit(1)+ term.OutputErrorAndExit("Error reading temporary file: %v", err)}prompt := string(bytes)err = os.Remove(tempFile.Name())if err != nil {- fmt.Fprintln(os.Stderr, "Error removing temporary file:", err)- os.Exit(1)+ term.OutputErrorAndExit("Error removing temporary file: %v", err)}prompt = strings.TrimPrefix(prompt, strings.TrimSpace(instructions))diff --git a/app/cli/lib/active_stream.go b/app/cli/lib/active_stream.goindex 9074ef23..8f80c090 100644--- a/app/cli/lib/active_stream.go+++ b/app/cli/lib/active_stream.go@@ -2,7 +2,6 @@ package libimport ("fmt"- "os""plandex/api""plandex/term"@@ -13,7 +12,7 @@ func SelectActiveStream(args []string) (string, string, bool) {res, apiErr := api.Client.ListPlansRunning([]string{CurrentProjectId}, false)if apiErr != nil {- fmt.Println("Error getting running plans:", apiErr)+ term.OutputErrorAndExit("Error getting running plans: %v", apiErr)return "", "", false}@@ -69,8 +68,7 @@ func SelectActiveStream(args []string) (string, string, bool) {selected, err := term.SelectFromList("Select an active plan", opts)if err != nil {- fmt.Fprintln(os.Stderr, "Error selecting plan:", err)- return "", "", false+ term.OutputErrorAndExit("Error selecting plan: %v", err)}for _, p := range res.PlansById {@@ -134,8 +132,7 @@ func SelectActiveStream(args []string) (string, string, bool) {selected, err := term.SelectFromList("Select a branch", opts)if err != nil {- fmt.Fprintln(os.Stderr, "Error selecting branch:", err)- return "", "", false+ term.OutputErrorAndExit("Error selecting branch: %v", err)}branch = selecteddiff --git a/app/cli/lib/apply.go b/app/cli/lib/apply.goindex d4de1a6c..fdd66825 100644--- a/app/cli/lib/apply.go+++ b/app/cli/lib/apply.go@@ -130,13 +130,13 @@ func ApplyPlan(planId, branch string, autoConfirm bool) error {// clear any partially applied changes before popping the stasherr := GitClearUncommittedChanges()if err != nil {- fmt.Printf("failed to clear uncommitted changes: %v\n", err)+ term.OutputErrorAndExit("Failed to clear uncommitted changes: %v", err)}}err := GitStashPop(true)if err != nil {- fmt.Printf("failed to pop git stash: %v\n", err)+ term.OutputErrorAndExit("Failed to pop git stash: %v", err)}}()}diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.goindex 4edb5f0f..af9577a8 100644--- a/app/cli/lib/context_load.go+++ b/app/cli/lib/context_load.go@@ -22,8 +22,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {onErr := func(err error) {term.StopSpinner()- fmt.Fprintf(os.Stderr, "Failed to load context: %v\n", err)- os.Exit(1)+ term.OutputErrorAndExit("Failed to load context: %v", err)}var loadContextReq shared.LoadContextRequest@@ -252,8 +251,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {if res.MaxTokensExceeded {overage := res.TotalTokens - res.MaxTokens- fmt.Printf("π¨ Update would add %d πͺ and exceed token limit (%d) by %d πͺ\n", res.TokensAdded, res.MaxTokens, overage)- os.Exit(1)+ term.OutputErrorAndExit("Update would add %d πͺ and exceed token limit (%d) by %d πͺ\n", res.TokensAdded, res.MaxTokens, overage)}if hasConflicts {diff --git a/app/cli/lib/context_update.go b/app/cli/lib/context_update.goindex 08204a3c..d9f22cb2 100644--- a/app/cli/lib/context_update.go+++ b/app/cli/lib/context_update.go@@ -113,8 +113,7 @@ func MustUpdateContext(maybeContexts []*shared.Context) {if err != nil {term.StopSpinner()- fmt.Fprintln(os.Stderr, "Error updating context:", err)- os.Exit(1)+ term.OutputErrorAndExit("Error updating context: %v", err)}term.StopSpinner()diff --git a/app/cli/lib/current.go b/app/cli/lib/current.goindex 32ef6f91..d5434ba7 100644--- a/app/cli/lib/current.go+++ b/app/cli/lib/current.go@@ -45,7 +45,7 @@ func resolveProject(mustResolve, shouldCreate bool) {"π€·ββοΈ No plans in current directory\nTry %s to create a plan or %s to see plans in nearby directories\n",color.New(color.Bold, color.FgHiCyan).Sprint("plandex new"),color.New(color.Bold, color.FgHiCyan).Sprint("plandex plans"))- os.Exit(1)+ os.Exit(0)}if fs.PlandexDir == "" {diff --git a/app/cli/main.go b/app/cli/main.goindex 6f8fe859..f704f036 100644--- a/app/cli/main.go+++ b/app/cli/main.go@@ -1,7 +1,6 @@package mainimport (- "fmt""log""os""path/filepath"@@ -11,6 +10,7 @@ import ("plandex/fs""plandex/lib""plandex/plan_exec"+ "plandex/term""github.com/plandex/plandex/shared")@@ -33,8 +33,7 @@ func init() {file, err := os.OpenFile(filepath.Join(fs.HomePlandexDir, "plandex.log"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)if err != nil {- fmt.Fprintf(os.Stderr, "Error opening log file: %v\n", err)- os.Exit(1)+ term.OutputErrorAndExit("Error opening log file: %v", err)}// Set the output of the logger to the filediff --git a/app/cli/plan_exec/build.go b/app/cli/plan_exec/build.goindex 2f5a7aeb..473e3712 100644--- a/app/cli/plan_exec/build.go+++ b/app/cli/plan_exec/build.go@@ -10,7 +10,6 @@ import (streamtui "plandex/stream_tui""plandex/term"- "github.com/fatih/color""github.com/plandex/plandex/shared")@@ -20,8 +19,7 @@ func Build(params ExecParams, buildBg bool) (bool, error) {contexts, apiErr := api.Client.ListContext(params.CurrentPlanId, params.CurrentBranch)if apiErr != nil {- color.New(color.FgRed).Fprintln(os.Stderr, "Error getting context:", apiErr)- os.Exit(1)+ term.OutputErrorAndExit("Error getting context: %v", apiErr)}anyOutdated, didUpdate, _ := params.CheckOutdatedContext(false, contexts)@@ -35,7 +33,6 @@ func Build(params ExecParams, buildBg bool) (bool, error) {projectPaths, _, err := fs.GetProjectPaths(fs.GetBaseDirForContexts(contexts))if err != nil {- fmt.Fprintln(os.Stderr, "Error getting project paths:", err)return false, fmt.Errorf("error getting project paths: %v", err)}@@ -53,7 +50,6 @@ func Build(params ExecParams, buildBg bool) (bool, error) {return false, nil}- fmt.Fprintln(os.Stderr, "Error building plan:", apiErr.Msg)return false, fmt.Errorf("error building plan: %v", apiErr.Msg)}diff --git a/app/cli/plan_exec/tell.go b/app/cli/plan_exec/tell.goindex b18675ed..08f395ea 100644--- a/app/cli/plan_exec/tell.go+++ b/app/cli/plan_exec/tell.go@@ -11,7 +11,6 @@ import (streamtui "plandex/stream_tui""plandex/term"- "github.com/fatih/color""github.com/plandex/plandex/shared")@@ -26,8 +25,7 @@ func TellPlan(contexts, apiErr := api.Client.ListContext(params.CurrentPlanId, params.CurrentBranch)if apiErr != nil {- color.New(color.FgRed).Fprintln(os.Stderr, "Error getting context:", apiErr)- os.Exit(1)+ term.OutputErrorAndExit("Error getting context: %v", apiErr)}anyOutdated, didUpdate, canceled := params.CheckOutdatedContext(true, contexts)@@ -45,8 +43,7 @@ func TellPlan(projectPaths, _, err := fs.GetProjectPaths(fs.GetBaseDirForContexts(contexts))if err != nil {- fmt.Fprintln(os.Stderr, "Error getting project paths:", err)- return+ term.OutputErrorAndExit("Error getting project paths: %v", err)}var fn func() bool@@ -84,15 +81,13 @@ func TellPlan(res, err := term.ConfirmYesNo("Upgrade now?")if err != nil {- fmt.Fprintln(os.Stderr, "Error prompting upgrade trial:", err)- return false+ term.OutputErrorAndExit("Error prompting upgrade trial: %v", err)}if res {err := auth.ConvertTrial()if err != nil {- fmt.Fprintln(os.Stderr, "Error converting trial:", err)- return false+ term.OutputErrorAndExit("Error converting trial: %v", err)}// retry action after converting trialreturn fn()@@ -100,13 +95,12 @@ func TellPlan(return false}- fmt.Fprintln(os.Stderr, "Prompt error:", apiErr.Msg)- return false+ term.OutputErrorAndExit("Prompt error: %v", apiErr.Msg)} else if apiErr != nil && isUserContinue && apiErr.Type == shared.ApiErrorTypeContinueNoMessages {fmt.Println("π€·ββοΈ There's no plan yet to continue")fmt.Println()term.PrintCmds("", "tell")- os.Exit(1)+ os.Exit(0)}if !tellBg {@@ -114,8 +108,7 @@ func TellPlan(err := streamtui.StartStreamUI(prompt, false)if err != nil {- log.Printf("Error starting stream UI: %v\n", err)- os.Exit(1)+ term.OutputErrorAndExit("Error starting stream UI: %v", err)}fmt.Println()diff --git a/app/cli/term/errors.go b/app/cli/term/errors.goindex 21381410..b6b391d9 100644--- a/app/cli/term/errors.go+++ b/app/cli/term/errors.go@@ -3,10 +3,39 @@ package termimport ("fmt""os"+ "strings""github.com/fatih/color"+ "github.com/plandex/plandex/shared")-func OutputNoApiKeyMsg() {+func OutputNoApiKeyMsgAndExit() {fmt.Fprintln(os.Stderr, color.New(color.Bold, color.FgHiRed).Sprintln("\nπ¨ OPENAI_API_KEY environment variable is not set.")+color.New().Sprintln("\nSet it with:\n\nexport OPENAI_API_KEY=your-api-key\n\nThen try again.\n\nπ If you don't have an OpenAI account, sign up here β https://platform.openai.com/signup\n\nπ Generate an api key here β https://platform.openai.com/api-keys"))+ os.Exit(1)+}++func OutputErrorAndExit(msg string, args ...interface{}) {+ msg = fmt.Sprintf(msg, args...)++ displayMsg := ""+ errorParts := strings.Split(msg, ": ")++ if len(errorParts) > 1 {+ for i, part := range errorParts {+ if i != 0 {+ displayMsg += "\n"+ }+ // indent the error message+ for n := 0; n < i; n++ {+ displayMsg += " "+ }++ displayMsg += "β " + shared.Capitalize(part)+ }+ } else {+ displayMsg = shared.Capitalize(msg)+ }++ fmt.Fprintln(os.Stderr, color.New(color.FgHiRed, color.Bold).Sprint("π¨ "+displayMsg))+ os.Exit(1)}diff --git a/app/cli/term/term.go b/app/cli/term/term.goindex cf53867f..3bf65c3c 100644--- a/app/cli/term/term.go+++ b/app/cli/term/term.go@@ -2,6 +2,7 @@ package termimport ("fmt"+ "log""os""os/exec""strings"@@ -109,7 +110,7 @@ func PageOutput(output string) {cmd.Stderr = os.Stderrif err := cmd.Run(); err != nil {- fmt.Fprintln(os.Stderr, "Failed to page output:", err)+ OutputErrorAndExit("Failed to page output: %v", err)}}@@ -123,7 +124,7 @@ func PageOutputReverse(output string) {cmd.Env = append(os.Environ(), "LESS=FRX", "LESSCHARSET=utf-8")if err := cmd.Run(); err != nil {- fmt.Fprintln(os.Stderr, "Failed to page output with colors:", err)+ OutputErrorAndExit("Failed to page output: %v", err)}}@@ -131,7 +132,7 @@ func GetDivisionLine() string {// Get the terminal widthterminalWidth, err := getTerminalWidth()if err != nil {- fmt.Println("Error fetching terminal size:", err)+ log.Println("Error fetching terminal size:", err)terminalWidth = 50 // default width if unable to fetch width}return strings.Repeat("β", terminalWidth)diff --git a/app/cli/url/url.go b/app/cli/url/url.goindex 553e6872..eed30e09 100644--- a/app/cli/url/url.go+++ b/app/cli/url/url.go@@ -2,11 +2,10 @@ package urlimport ("errors"- "fmt""io""net/http""net/url"- "os"+ "plandex/term""regexp""strings""time"@@ -62,8 +61,7 @@ func ExtractTextualContent(htmlContent string) string {r := strings.NewReader(htmlContent)doc, err := goquery.NewDocumentFromReader(r)if err != nil {- fmt.Fprintf(os.Stderr, "Failed to parse HTML: %v\n", err)- os.Exit(1)+ term.OutputErrorAndExit("Failed to parse HTML: %v", err)}return doc.Text()diff --git a/app/shared/utils.go b/app/shared/utils.goindex 5a31b584..63c90f8d 100644--- a/app/shared/utils.go+++ b/app/shared/utils.go@@ -56,3 +56,10 @@ func Dasherize(s string) string {func Compact(s string) string {return strings.ReplaceAll(Dasherize(s), "-", "")}++func Capitalize(s string) string {+ if s == "" {+ return ""+ }+ return strings.ToUpper(s[:1]) + s[1:]+}