DUP-GO-8: resolvePort + json.Marshal + postJSON pattern repeated 9 times in operations.go #43

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

Summary

Nine consecutive mutating operations in internal/platforms/opencode/operations.go (lines 330–494) all follow the same 8–12 line pattern:

port, _, err := a.resolvePort(req.SessionID)
if err != nil { return err }
payload, err := json.Marshal(...)
if err != nil { return fmt.Errorf("marshal request: %w", err) }
return postJSON(ctx, port, fmt.Sprintf("/session/%s/...", req.SessionID), payload)

The fmt.Errorf("marshal request: %w", err) wrapping appears identically 8 times.

Fix

Extract a marshalOrErr(v any) ([]byte, error) helper for the marshal step. Consider a table-driven approach for the nine operations to reduce the file further.

Effort

Medium.

## Summary Nine consecutive mutating operations in `internal/platforms/opencode/operations.go` (lines 330–494) all follow the same 8–12 line pattern: ```go port, _, err := a.resolvePort(req.SessionID) if err != nil { return err } payload, err := json.Marshal(...) if err != nil { return fmt.Errorf("marshal request: %w", err) } return postJSON(ctx, port, fmt.Sprintf("/session/%s/...", req.SessionID), payload) ``` The `fmt.Errorf("marshal request: %w", err)` wrapping appears identically 8 times. ## Fix Extract a `marshalOrErr(v any) ([]byte, error)` helper for the marshal step. Consider a table-driven approach for the nine operations to reduce the file further. ## Effort Medium.
dries closed this issue 2026-07-04 19:53:55 +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#43
No description provided.