Skip to content

Commit 1390708

Browse files
committed
fix: add default cases to switch statements for model format handling
1 parent d1b12a8 commit 1390708

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

AGENTS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ If any step fails, fix the issue and re-run before committing.
2323
- **golangci-lint v2.7.2+**[Install instructions](https://golangci-lint.run/welcome/install/)
2424
- **ShellCheck**`brew install shellcheck` (macOS) or `apt-get install shellcheck` (Linux)
2525

26+
## Linting
27+
28+
- **Never use `//nolint:exhaustive`** to suppress the `exhaustive` linter.
29+
Instead, always cover all cases in `switch` statements on enum types — either
30+
by listing every value explicitly or by including a `default:` branch. This
31+
ensures that when a new value is added to the enum, the linter flags any
32+
switch that doesn't handle it, preventing silent bugs.
33+
2634
## Testing
2735

2836
When adding a new Go package that contains tests, include a

pkg/distribution/internal/partial/partial.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ func matchesMediaType(layerMT, targetMT oci.MediaType, modelFormat string) bool
238238
}
239239

240240
// Native ModelPack support: check format-specific ModelPack types
241-
//nolint:exhaustive // Only GGUF and Safetensors need cross-format matching
242241
switch targetMT {
243242
case types.MediaTypeGGUF:
244243
if layerMT == modelpack.MediaTypeWeightGGUF {
@@ -248,6 +247,8 @@ func matchesMediaType(layerMT, targetMT oci.MediaType, modelFormat string) bool
248247
if layerMT == modelpack.MediaTypeWeightSafetensors {
249248
return true
250249
}
250+
default:
251+
// No format-specific ModelPack mapping for this media type
251252
}
252253

253254
// ModelPack model-spec support: format-agnostic weight types (.raw, .tar, etc.)
@@ -256,14 +257,15 @@ func matchesMediaType(layerMT, targetMT oci.MediaType, modelFormat string) bool
256257
// in their media type and are handled above; applying this fallback to them would
257258
// cause cross-format false positives (e.g., safetensors layer matching as GGUF).
258259
if modelFormat != "" && modelpack.IsModelPackGenericWeightMediaType(string(layerMT)) {
259-
//nolint:exhaustive // Only weight formats need cross-format matching
260260
switch targetMT {
261261
case types.MediaTypeGGUF:
262262
return modelFormat == string(types.FormatGGUF)
263263
case types.MediaTypeSafetensors:
264264
return modelFormat == string(types.FormatSafetensors)
265265
case types.MediaTypeDDUF:
266266
return modelFormat == string(types.FormatDDUF) || modelFormat == string(types.FormatDiffusers) //nolint:staticcheck // FormatDiffusers kept for backward compatibility
267+
default:
268+
// No generic weight resolution for this media type
267269
}
268270
}
269271

0 commit comments

Comments
 (0)