"vscode:/vscode.git/clone" did not exist on "6b727842d7fd370ac057c092d913bf8557dd32c2"
Unverified Commit 7ba13085 authored by Bruce MacDonald's avatar Bruce MacDonald Committed by GitHub
Browse files

Merge pull request #147 from jmorganca/brucemacd/cli-err-display

Improve CLI error display
parents 91cd5401 09dc6273
...@@ -27,7 +27,7 @@ func checkError(resp *http.Response, body []byte) error { ...@@ -27,7 +27,7 @@ func checkError(resp *http.Response, body []byte) error {
err := json.Unmarshal(body, &apiError) err := json.Unmarshal(body, &apiError)
if err != nil { if err != nil {
// Use the full body as the message if we fail to decode a response. // Use the full body as the message if we fail to decode a response.
apiError.Message = string(body) apiError.ErrorMessage = string(body)
} }
return apiError return apiError
...@@ -92,7 +92,6 @@ func (c *Client) do(ctx context.Context, method, path string, reqData, respData ...@@ -92,7 +92,6 @@ func (c *Client) do(ctx context.Context, method, path string, reqData, respData
} }
} }
return nil return nil
} }
func (c *Client) stream(ctx context.Context, method, path string, data any, fn func([]byte) error) error { func (c *Client) stream(ctx context.Context, method, path string, data any, fn func([]byte) error) error {
...@@ -139,7 +138,7 @@ func (c *Client) stream(ctx context.Context, method, path string, data any, fn f ...@@ -139,7 +138,7 @@ func (c *Client) stream(ctx context.Context, method, path string, data any, fn f
return StatusError{ return StatusError{
StatusCode: response.StatusCode, StatusCode: response.StatusCode,
Status: response.Status, Status: response.Status,
Message: errorResponse.Error, ErrorMessage: errorResponse.Error,
} }
} }
......
...@@ -10,14 +10,21 @@ import ( ...@@ -10,14 +10,21 @@ import (
type StatusError struct { type StatusError struct {
StatusCode int StatusCode int
Status string Status string
Message string ErrorMessage string `json:"error"`
} }
func (e StatusError) Error() string { func (e StatusError) Error() string {
if e.Message != "" { switch {
return fmt.Sprintf("%s: %s", e.Status, e.Message) case e.Status != "" && e.ErrorMessage != "":
} return fmt.Sprintf("%s: %s", e.Status, e.ErrorMessage)
case e.Status != "":
return e.Status return e.Status
case e.ErrorMessage != "":
return e.ErrorMessage
default:
// this should not happen
return "something went wrong, please see the ollama server logs for details"
}
} }
type GenerateRequest struct { type GenerateRequest struct {
......
...@@ -2,6 +2,7 @@ package server ...@@ -2,6 +2,7 @@ package server
import ( import (
"encoding/json" "encoding/json"
"errors"
"io" "io"
"log" "log"
"net" "net"
...@@ -178,6 +179,10 @@ func ListModelsHandler(c *gin.Context) { ...@@ -178,6 +179,10 @@ func ListModelsHandler(c *gin.Context) {
} }
err = filepath.Walk(fp, func(path string, info os.FileInfo, err error) error { err = filepath.Walk(fp, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
if errors.Is(err, os.ErrNotExist) {
log.Printf("manifest file does not exist: %s", fp)
return nil
}
return err return err
} }
if !info.IsDir() { if !info.IsDir() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment