main.go 684 B

123456789101112131415161718192021222324252627282930313233
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "os"
  6. "github.com/ollama/ollama/api"
  7. "github.com/ollama/ollama/cmd"
  8. )
  9. func main() {
  10. checkErr(cmd.NewCLI().ExecuteContext(context.Background()))
  11. }
  12. // checkErr prints the error message and exits the program if the message is not nil.
  13. func checkErr(msg any) {
  14. if msg == nil {
  15. return
  16. }
  17. if errorResponse, ok := msg.(api.ErrorResponse); ok {
  18. // This error contains some additional information that we want to print
  19. fmt.Fprintln(os.Stderr, "Error: ", errorResponse.Err)
  20. if errorResponse.Hint != "" {
  21. fmt.Fprintf(os.Stderr, "\n%s\n", errorResponse.Hint)
  22. }
  23. os.Exit(1)
  24. }
  25. fmt.Fprintln(os.Stderr, "Error: ", msg)
  26. os.Exit(1)
  27. }