Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/inference/models/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"strings"
"sync"

"github.com/docker/model-runner/pkg/diskusage"
"github.com/docker/model-runner/pkg/distribution/distribution"
"github.com/docker/model-runner/pkg/distribution/registry"
"github.com/docker/model-runner/pkg/distribution/types"
"github.com/docker/model-runner/pkg/diskusage"
"github.com/docker/model-runner/pkg/inference"
"github.com/docker/model-runner/pkg/inference/memory"
"github.com/docker/model-runner/pkg/logging"
Expand Down Expand Up @@ -196,6 +196,11 @@ func (m *Manager) handleCreateModel(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Model not found", http.StatusNotFound)
return
}
if errors.Is(err, distribution.ErrUnsupportedFormat) {
m.log.Warnf("Unsupported model format for %q: %v", request.From, err)
http.Error(w, distribution.ErrUnsupportedFormat.Error(), http.StatusBadRequest)
return
}
Comment on lines +199 to +203
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this new error handling for ErrUnsupportedFormat is a great addition and returns a clear message to the user, it highlights an inconsistency in how errors are reported in this function. Some errors return a generic, hardcoded string (e.g., for ErrModelNotFound), while the default case returns the full wrapped err.Error().

For better consistency and an improved user experience, consider refactoring the other error handling cases in handleCreateModel to also return more specific and helpful error messages, similar to what you've done here. This could be addressed in a follow-up PR to keep this change focused.

For example, for ErrModelNotFound:

// Before
http.Error(w, "Model not found", http.StatusNotFound)

// After (suggested)
http.Error(w, err.Error(), http.StatusNotFound)

This would provide more context to the user, which is a pattern already used by other handlers in this file, such as handleDeleteModel.

http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand Down
Loading