Skip to content

feat: add error handling for unsupported model formats in manager#192

Merged
ilopezluna merged 2 commits intomainfrom
handle-format-error
Oct 3, 2025
Merged

feat: add error handling for unsupported model formats in manager#192
ilopezluna merged 2 commits intomainfrom
handle-format-error

Conversation

@ilopezluna
Copy link
Contributor

@ilopezluna ilopezluna commented Oct 2, 2025

Before:

MODEL_RUNNER_HOST=http://localhost:13434 docker model pull aistaging/smollm2-vllm
Failed to pull model: pulling aistaging/smollm2-vllm failed with status 500 Internal Server Error: error while pulling model: safetensors models are not currently supported - this runner only supports GGUF format models

After:

MODEL_RUNNER_HOST=http://localhost:13434 docker model pull aistaging/smollm2-vllm
Failed to pull model: pulling aistaging/smollm2-vllm failed with status 400 Bad Request: safetensors models are not currently supported - this runner only supports GGUF format models

Summary by Sourcery

Handle unsupported model format errors in the manager by returning a Bad Request status and logging a warning instead of an Internal Server Error.

Bug Fixes:

  • Return HTTP 400 Bad Request for unsupported model formats instead of HTTP 500 Internal Server Error

Enhancements:

  • Log a warning when an unsupported model format is encountered in the model creation handler

Copilot AI review requested due to automatic review settings October 2, 2025 14:40
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 2, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR introduces an explicit check for unsupported model formats in the Manager’s create endpoint—returning a 400 Bad Request with a warning log instead of a 500—and cleans up a duplicate diskusage import.

Sequence diagram for error handling in model creation (unsupported format)

sequenceDiagram
participant Client
participant Manager
participant Distribution
Client->>Manager: POST /models (create model)
Manager->>Distribution: Request model pull
Distribution-->>Manager: Return ErrUnsupportedFormat
Manager->>Manager: Log warning
Manager->>Client: 400 Bad Request (unsupported format)
Loading

Class diagram for Manager error handling update

classDiagram
class Manager {
  +handleCreateModel(w, r)
}
class Distribution {
  +ErrUnsupportedFormat
}
Manager --> Distribution: uses
Loading

File-Level Changes

Change Details Files
Add specific error handling for unsupported model formats
  • Check for ErrUnsupportedFormat after model pull fails
  • Log a warning when encountering an unsupported format
  • Return HTTP 400 Bad Request with the error message
pkg/inference/models/manager.go
Reorder and de-duplicate diskusage import
  • Move diskusage import to the top of the import block
  • Remove the duplicate diskusage import
pkg/inference/models/manager.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ilopezluna ilopezluna requested a review from a team October 2, 2025 14:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves error handling in the model manager by adding specific handling for unsupported model formats, changing the HTTP status code from 500 Internal Server Error to 400 Bad Request when attempting to pull models in unsupported formats like safetensors.

Key Changes

  • Added specific error handling for distribution.ErrUnsupportedFormat with appropriate 400 status code
  • Reordered import statements for better organization

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ilopezluna, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the error handling logic within the model manager. It introduces a more precise HTTP status code for scenarios where a client attempts to pull a model in an unsupported format, transitioning from a generic server error to a specific client-side error. This change enhances the clarity and correctness of API responses, allowing clients to better understand and react to invalid requests.

Highlights

  • Improved Error Handling: The system now provides more specific error responses when an unsupported model format is encountered during a model pull operation.
  • HTTP Status Code Change: Requests attempting to pull models in unsupported formats will now receive an HTTP 400 Bad Request status code, instead of an HTTP 500 Internal Server Error, for better client-side error identification.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Consider centralizing the mapping of distribution.ErrUnsupportedFormat to HTTP Bad Request status in a shared error-handling utility so that handlers remain concise and consistent.
  • It may be better to return a more user-friendly error message instead of the raw ErrUnsupportedFormat.Error() to avoid exposing internal implementation details.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider centralizing the mapping of distribution.ErrUnsupportedFormat to HTTP Bad Request status in a shared error-handling utility so that handlers remain concise and consistent.
- It may be better to return a more user-friendly error message instead of the raw ErrUnsupportedFormat.Error() to avoid exposing internal implementation details.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly improves error handling for unsupported model formats by returning a 400 Bad Request instead of a 500 Internal Server Error. The change is well-implemented and provides a much clearer error message to the end-user. I have one suggestion regarding error handling consistency that could be addressed in a follow-up to further improve code quality.

Comment on lines +199 to +203
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
}
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.

Co-authored-by: Dorin-Andrei Geman <dorin.geman@docker.com>
Copilot AI review requested due to automatic review settings October 3, 2025 07:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}
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.StatusUnsupportedMediaType)
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

The HTTP status code should be http.StatusBadRequest (400) to match the PR description and expected behavior, not http.StatusUnsupportedMediaType (415).

Suggested change
http.Error(w, distribution.ErrUnsupportedFormat.Error(), http.StatusUnsupportedMediaType)
http.Error(w, distribution.ErrUnsupportedFormat.Error(), http.StatusBadRequest)

Copilot uses AI. Check for mistakes.
@ilopezluna ilopezluna merged commit 2d31939 into main Oct 3, 2025
5 checks passed
@ilopezluna ilopezluna deleted the handle-format-error branch October 3, 2025 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants