Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 7, 2026

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Add error context wrapping to plain errors.New() calls</issue_title>
<issue_description>## Objective

Convert 80 instances of errors.New() to properly wrapped errors using fmt.Errorf with %w to preserve error chains and prevent context loss.

Context

Currently 80 plain errors.New() calls lose valuable error chain context, making debugging difficult. This contrasts with the 809 (55.8%) properly wrapped errors elsewhere in the codebase. Preserving error chains enables better error analysis and debugging.

Files to Modify

Focus on validation files in pkg/workflow/:

  • pkg/workflow/mcp-config.go (999 LOC)
  • pkg/workflow/safe_outputs_config_generation.go (854 LOC)
  • pkg/workflow/validation*.go files (63 validation files total)
  • Other pkg/workflow/*.go files with plain errors.New() usage

Approach

Replace plain error creation with wrapped errors:

// OLD - Loses context
return errors.New("validation failed")

// NEW - Preserves context (when underlying error exists)
return fmt.Errorf("validation failed: %w", underlyingErr)

// OR - Add actionable context (when no underlying error)
return fmt.Errorf("validation failed: field '%s' is required but not provided. Add the field to your workflow frontmatter", fieldName)

Key principles:

  1. Use %w (not %v) to preserve error chains for errors.Is() and errors.As() checks
  2. Add actionable context: what failed, why, what to do
  3. Include specific values in error messages (field names, etc.)

Acceptance Criteria

  • All errors.New() calls in pkg/workflow/ reviewed
  • Context-sensitive errors converted to fmt.Errorf with %w wrapping
  • Error messages include actionable context (what/why/how to fix)
  • No regression in error handling tests
  • Error chains preserve root cause information

Validation

Run after changes:

make test-unit
# Check improvement in wrapping ratio
grep -r "fmt.Errorf.*%w" pkg/workflow/ | wc -l
grep -r "errors.New" pkg/workflow/ | wc -l

Related to #9236

AI generated by Plan Command for discussion #9231

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[plan] Add error context wrapping to plain errors.New() calls

3 participants