diff --git a/api/types.go b/api/types.go index e986000f8..f8fa481f3 100644 --- a/api/types.go +++ b/api/types.go @@ -647,7 +647,10 @@ type ErrorResponse struct { } func (e ErrorResponse) Error() string { - return e.Err + if e.Hint == "" { + return e.Err + } + return fmt.Sprintf("%s\n%s", e.Err, e.Hint) } // FormatParams converts specified parameter options to their correct types diff --git a/main.go b/main.go index 2992ed5c3..650e03a63 100644 --- a/main.go +++ b/main.go @@ -2,31 +2,12 @@ package main import ( "context" - "fmt" - "os" - "github.com/ollama/ollama/api" + "github.com/spf13/cobra" + "github.com/ollama/ollama/cmd" ) func main() { - checkErr(cmd.NewCLI().ExecuteContext(context.Background())) -} - -// checkErr prints the error message and exits the program if the message is not nil. -func checkErr(err any) { - if err == nil { - return - } - - switch e := err.(type) { - case api.ErrorResponse: - fmt.Fprintln(os.Stderr, "Error: ", e.Err) - if e.Hint != "" { - fmt.Fprintf(os.Stderr, "\n%s\n", e.Hint) - } - default: - fmt.Fprintln(os.Stderr, "Error: ", err) - } - os.Exit(1) + cobra.CheckErr(cmd.NewCLI().ExecuteContext(context.Background())) } diff --git a/server/routes.go b/server/routes.go index c87dedf2b..3dba8ba59 100644 --- a/server/routes.go +++ b/server/routes.go @@ -596,7 +596,7 @@ func (s *Server) PullHandler(c *gin.Context) { if errors.As(err, &e) { hint := fmt.Sprintf("Model %q not found - please check the model name is correct and try again", reqName) if name.Host == DefaultRegistry { - hint = fmt.Sprintf("Model %q not found - search available models at https://ollama.com/search?q=%s", reqName, reqName) + hint = fmt.Sprintf("Model %q not found - search available models at: https://ollama.com/search?q=%s", reqName, reqName) } ch <- api.ErrorResponse{ Err: err.Error(),