Skip to content

[Code Quality] Deduplicate 13 identical "failed to marshal JSON" error wraps in pkg/cli #50963

Description

@github-actions

Description

An error-message quality audit (discussion #50886) found 13 call sites across pkg/cli using the identical bare wrapper fmt.Errorf("failed to marshal JSON: %w", err), including outcomes_command.go:196, deps_report.go:249, and run_workflow_execution.go:612. This provides no context on what failed to marshal, making debugging harder.

Suggested Changes

Introduce a small shared helper in an existing pkg/cli utility file:

func marshalJSONOrWrap(v any, context string) ([]byte, error) {
    data, err := json.Marshal(v)
    if err != nil {
        return nil, fmt.Errorf("failed to marshal %s to JSON: %w", context, err)
    }
    return data, nil
}

Replace the 13 call sites with calls to this helper, passing a short descriptive context string (e.g. "outcomes report", "dependency report", "run execution result").

Files Affected

  • pkg/cli/outcomes_command.go:196
  • pkg/cli/deps_report.go:249
  • pkg/cli/run_workflow_execution.go:612
  • ~10 other pkg/cli files with the identical pattern

Success Criteria

  • Shared helper exists and is used by at least the 3 identified files (ideally all 13)
  • Error messages include which output/context failed to marshal
  • Existing tests referencing old error text are updated
  • make test-unit passes

Source

Extracted from Repository Quality Improvement Report - Error Message & Diagnostics Quality (discussion #50886)

Priority

Medium - improves debuggability, low risk mechanical change

🔍 Task mining by Discussion Task Miner - Code Quality Improvement Agent · auto · 35.3 AIC · ⌖ 4.12 AIC · ⊞ 10.2K ·

  • expires on Aug 7, 2026, 5:44 PM UTC-08:00

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions