Browse Source

use errors.Is

Bruce MacDonald 2 months ago
parent
commit
2de832552a
2 changed files with 3 additions and 8 deletions
  1. 2 6
      server/images.go
  2. 1 2
      server/routes.go

+ 2 - 6
server/images.go

@@ -629,11 +629,7 @@ func PullModel(ctx context.Context, name string, regOpts *registryOptions, fn fu
 	return nil
 }
 
-type ErrRemoteModelNotFound struct{}
-
-func (ErrRemoteModelNotFound) Error() string {
-	return "model not found"
-}
+var ErrRemoteModelNotFound = errors.New("model not found")
 
 func pullModelManifest(ctx context.Context, mp ModelPath, regOpts *registryOptions) (*Manifest, error) {
 	requestURL := mp.BaseURL().JoinPath("v2", mp.GetNamespaceRepository(), "manifests", mp.Tag)
@@ -643,7 +639,7 @@ func pullModelManifest(ctx context.Context, mp ModelPath, regOpts *registryOptio
 	resp, err := makeRequestWithRetry(ctx, http.MethodGet, requestURL, headers, nil, regOpts)
 	if errors.Is(err, os.ErrNotExist) {
 		// The model was not found on the remote registry
-		return nil, fmt.Errorf("%w: %s", ErrRemoteModelNotFound{}, err)
+		return nil, fmt.Errorf("%w: %s", ErrRemoteModelNotFound, err)
 	} else if err != nil {
 		return nil, err
 	}

+ 1 - 2
server/routes.go

@@ -592,8 +592,7 @@ func (s *Server) PullHandler(c *gin.Context) {
 		defer cancel()
 
 		if err := PullModel(ctx, name.DisplayShortest(), regOpts, fn); err != nil {
-			var e ErrRemoteModelNotFound
-			if errors.As(err, &e) {
+			if errors.Is(err, ErrRemoteModelNotFound) {
 				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)