DUP-GO-4: ErrUnsupported fallback pattern duplicated in handleSessionChanges and handleSessionInfo #45

Closed
opened 2026-05-27 16:57:15 +02:00 by dries · 0 comments
Owner

Summary

handleSessionChanges (lines 474–493) and handleSessionInfo (lines 497–519) in internal/server/handlers_sessions.go both have the same two-tier error handling structure:

  1. Check errors.Is(err, platforms.ErrUnsupported) → return zeroed-out response
  2. Call writePlatformError for other errors

Both also manually nil-guard nested slices on the returned struct before writing JSON. The pattern is ~15 lines each.

Fix

Extract a withUnsupportedFallback[T](w, err, zero T) helper using generics.

Effort

Trivial.

## Summary `handleSessionChanges` (lines 474–493) and `handleSessionInfo` (lines 497–519) in `internal/server/handlers_sessions.go` both have the same two-tier error handling structure: 1. Check `errors.Is(err, platforms.ErrUnsupported)` → return zeroed-out response 2. Call `writePlatformError` for other errors Both also manually nil-guard nested slices on the returned struct before writing JSON. The pattern is ~15 lines each. ## Fix Extract a `withUnsupportedFallback[T](w, err, zero T)` helper using generics. ## Effort Trivial.
dries closed this issue 2026-07-11 11:23:18 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dries/ocman#45
No description provided.