[PR #14714] llm: use %w instead of %v for proper error wrapping #14806

Open
opened 2026-04-13 01:02:58 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14714
Author: @gambletan
Created: 3/8/2026
Status: 🔄 Open

Base: mainHead: fix/llm-server-error-wrapping


📝 Commits (1)

  • 6ba66cc llm: use %w instead of %v for error wrapping in server.go

📊 Changes

1 file changed (+6 additions, -6 deletions)

View changed files

📝 llm/server.go (+6 -6)

📄 Description

What

Replace %v with %w in fmt.Errorf calls throughout llm/server.go.

Why

Using %v to format errors in fmt.Errorf discards the error chain, making it impossible for callers to use errors.Is() or errors.As() to inspect the underlying cause. This matters for error handling in several cases:

  • Runner startup errors (line 291): callers can't check if the underlying error is a specific type like exec.Error or context.DeadlineExceeded
  • HTTP request creation errors (lines 1277, 1601): callers can't detect url.Error or similar
  • JSON marshaling/unmarshaling errors (lines 1595, 1650): callers can't distinguish between different JSON error types
  • Response reading errors (line 1692): callers can't check for io.EOF or network errors

The %w verb was introduced in Go 1.13 specifically to preserve the error chain in wrapped errors.

Change

Six %v%w replacements in fmt.Errorf calls in llm/server.go.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/14714 **Author:** [@gambletan](https://github.com/gambletan) **Created:** 3/8/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/llm-server-error-wrapping` --- ### 📝 Commits (1) - [`6ba66cc`](https://github.com/ollama/ollama/commit/6ba66ccd4a4e543f7396cb7ab7eb0babcc139851) llm: use %w instead of %v for error wrapping in server.go ### 📊 Changes **1 file changed** (+6 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `llm/server.go` (+6 -6) </details> ### 📄 Description ## What Replace `%v` with `%w` in `fmt.Errorf` calls throughout `llm/server.go`. ## Why Using `%v` to format errors in `fmt.Errorf` discards the error chain, making it impossible for callers to use `errors.Is()` or `errors.As()` to inspect the underlying cause. This matters for error handling in several cases: - **Runner startup errors** (line 291): callers can't check if the underlying error is a specific type like `exec.Error` or `context.DeadlineExceeded` - **HTTP request creation errors** (lines 1277, 1601): callers can't detect `url.Error` or similar - **JSON marshaling/unmarshaling errors** (lines 1595, 1650): callers can't distinguish between different JSON error types - **Response reading errors** (line 1692): callers can't check for `io.EOF` or network errors The `%w` verb was introduced in Go 1.13 specifically to preserve the error chain in wrapped errors. ## Change Six `%v` → `%w` replacements in `fmt.Errorf` calls in `llm/server.go`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 01:02:58 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#14806