mirror of
https://github.com/ollama/ollama.git
synced 2026-04-17 19:54:03 +02:00
fix: improve error message for unknown input item type in responses API (#15424)
The default branch in unmarshalResponsesInputItem had two issues: - It referenced typeField.Type instead of itemType; these differ when the shorthand role-based format promotes an empty type to "message", meaning an unhandled type would show the wrong value in the error string. - It used %s formatting, so an empty type field produced the unhelpful message "unknown input item type: " with no indication what was missing. Fix by using itemType (the resolved value) with %q quoting, and add a dedicated message when itemType is empty (both type and role absent): "input item missing required 'type' field". Tests added for the empty-type and missing-type cases. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -281,7 +281,10 @@ func unmarshalResponsesInputItem(data []byte) (ResponsesInputItem, error) {
|
||||
}
|
||||
return reasoning, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown input item type: %s", typeField.Type)
|
||||
if itemType == "" {
|
||||
return nil, fmt.Errorf("input item missing required 'type' field")
|
||||
}
|
||||
return nil, fmt.Errorf("unknown input item type: %q", itemType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -253,6 +253,29 @@ func TestUnmarshalResponsesInputItem(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Error("expected error, got nil")
|
||||
}
|
||||
if err != nil && err.Error() != `unknown input item type: "unknown_type"` {
|
||||
t.Errorf("unexpected error message: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("missing type field", func(t *testing.T) {
|
||||
_, err := unmarshalResponsesInputItem([]byte(`{"content": "hello"}`))
|
||||
if err == nil {
|
||||
t.Error("expected error for missing type, got nil")
|
||||
}
|
||||
if err != nil && err.Error() != "input item missing required 'type' field" {
|
||||
t.Errorf("unexpected error message: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("empty type field", func(t *testing.T) {
|
||||
_, err := unmarshalResponsesInputItem([]byte(`{"type": ""}`))
|
||||
if err == nil {
|
||||
t.Error("expected error for empty type, got nil")
|
||||
}
|
||||
if err != nil && err.Error() != "input item missing required 'type' field" {
|
||||
t.Errorf("unexpected error message: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user