return hint in error function
This commit is contained in:
parent
68525466f2
commit
a5f2db3744
@ -647,7 +647,10 @@ type ErrorResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e ErrorResponse) Error() string {
|
func (e ErrorResponse) Error() string {
|
||||||
|
if e.Hint == "" {
|
||||||
return e.Err
|
return e.Err
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s\n%s", e.Err, e.Hint)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FormatParams converts specified parameter options to their correct types
|
// FormatParams converts specified parameter options to their correct types
|
||||||
|
25
main.go
25
main.go
@ -2,31 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/ollama/ollama/api"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/ollama/ollama/cmd"
|
"github.com/ollama/ollama/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
checkErr(cmd.NewCLI().ExecuteContext(context.Background()))
|
cobra.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)
|
|
||||||
}
|
}
|
||||||
|
@ -596,7 +596,7 @@ func (s *Server) PullHandler(c *gin.Context) {
|
|||||||
if errors.As(err, &e) {
|
if errors.As(err, &e) {
|
||||||
hint := fmt.Sprintf("Model %q not found - please check the model name is correct and try again", reqName)
|
hint := fmt.Sprintf("Model %q not found - please check the model name is correct and try again", reqName)
|
||||||
if name.Host == DefaultRegistry {
|
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{
|
ch <- api.ErrorResponse{
|
||||||
Err: err.Error(),
|
Err: err.Error(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user