Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

Validation errors appeared as plain text while other CLI errors used console formatting (✗ prefix, color styling), creating inconsistent user experience.

Changes

New validation output helpers (pkg/cli/validation_output.go):

  • FormatValidationError(err) - Applies console styling while preserving error structure
  • PrintValidationError(err) - Convenience wrapper for formatting + printing to stderr

Updated compile command (cmd/gh-aw/main.go):

  • Formats validation errors before returning to main error handler
  • Skips formatting in JSON mode to preserve structured output
  • Leverages existing detection of pre-formatted errors (checks for ✗ prefix)

Test coverage (pkg/cli/validation_output_test.go):

  • Verifies formatting applied without altering content
  • Tests simple errors, multi-line errors, and structured errors (e.g., GitHubToolsetValidationError)
  • Confirms nil handling and content integrity

Architecture

Maintains separation of concerns:

  • Validation layer (pkg/workflow, pkg/parser): Plain text errors - testable, reusable
  • CLI layer (pkg/cli, cmd/gh-aw): Applies console formatting via helpers

Example formatted output:

$ gh aw compile --dependabot test-workflow.md
✗ --dependabot flag cannot be used with specific workflow files

The helpers are available for future use in other commands that return validation errors.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Code Quality] Integrate console formatting with validation errors</issue_title>
<issue_description>### Description

Bridge the gap between validation errors (currently plain text) and CLI console formatting to provide consistent, styled error display. Currently 0 validation errors use console formatting, leading to inconsistent user experience between validation errors and other CLI output.

Current Situation

Console Formatting Gap:

  • 0 validation errors use console.FormatErrorMessage()
  • Validation errors appear as plain text without color/emphasis
  • Inconsistent with CLI command error handling patterns
  • 22 direct stderr writes bypass console formatting system
  • Users see unstyled errors in CLI context where other errors are styled

Current Pattern:

// CLI command (using console formatting)
fmt.Fprintln(os.Stderr, console.FormatErrorMessage("Failed to process"))

// Validation error (plain text, inconsistent)
fmt.Fprintln(os.Stderr, err)

Proposed Architecture

Design Principle: Separation of concerns

  • Validation layer: Plain text errors (testable, reusable, framework-agnostic)
  • CLI layer: Console formatting wrapper (user-facing, styled, accessible)

This approach:

  • ✅ Keeps validation logic pure and testable
  • ✅ Allows validation errors to be used in non-CLI contexts
  • ✅ Centralizes formatting logic in CLI layer
  • ✅ Maintains existing test coverage

Implementation Plan

Phase 1: Create Formatting Helper (Day 1)

Create pkg/cli/validation_output.go:

package cli

import (
    "fmt"
    "os"
    "strings"
    
    "github.com/githubnext/gh-aw/pkg/console"
)

// FormatValidationError formats validation errors for console output
// Preserves structured error content while applying console styling
func FormatValidationError(err error) string {
    if err == nil {
        return ""
    }
    
    errMsg := err.Error()
    
    // Detect multi-line structured errors (like GitHubToolsetValidationError)
    if strings.Contains(errMsg, "\n\n") || strings.HasPrefix(errMsg, "ERROR:") {
        // Preserve structure, apply styling to header only
        return console.FormatErrorMessage(errMsg)
    }
    
    // Standard single-line or simple multi-line error
    return console.FormatErrorMessage(errMsg)
}

// PrintValidationError prints a validation error to stderr with formatting
func PrintValidationError(err error) {
    if err == nil {
        return
    }
    fmt.Fprintln(os.Stderr, FormatValidationError(err))
}

Phase 2: Update CLI Commands (Day 1-2)

Pattern:

// OLD
if err := ValidateWorkflow(config); err != nil {
    fmt.Fprintln(os.Stderr, err)
    return err
}

// NEW
if err := ValidateWorkflow(config); err != nil {
    PrintValidationError(err)
    return err
}

Commands to update (minimum 5):

  1. pkg/cli/compile_command.go - RunCompileWorkflow
  2. pkg/cli/run_command.go - RunRunWorkflow
  3. pkg/cli/mcp_inspect_command.go - inspect operations
  4. pkg/cli/audit_command.go - validation failures
  5. pkg/cli/compile_validation.go - all validation error prints

Phase 3: Testing (Day 2)

Create pkg/cli/validation_output_test.go:

  • Verify styling applied correctly
  • Verify structured errors preserve formatting
  • Verify error content unchanged (only styling added)
  • Test both simple and complex error types

Example Transformation

Before:

$ gh aw compile invalid.md
missing required field 'engine'

After:

$ gh aw compile invalid.md
✖ missing required field 'engine'. Example:
  engine: copilot

(where ✖ and error text are styled with red color)

Success Criteria

  • New file pkg/cli/validation_output.go with FormatValidationError helper
  • Helper detects error types and formats appropriately
  • At least 5 CLI commands updated to use new formatting helper
  • Validation errors now displayed with console.FormatErrorMessage styling
  • Complex validation errors (like GitHubToolsetValidationError) preserve structure
  • Tests in validation_output_test.go verify formatting doesn't alter error content
  • Run make agent-finish successfully

Expected Outcomes

  • Consistent styled output for all CLI errors (validation + command)
  • Improved user experience with color/emphasis on errors
  • Better accessibility through console formatting system
  • Maintains validation layer purity (no CLI dependencies)

Priority

Medium - User experience improvement

Estimated Effort

Medium (1-2 days)

Files to Create

  • pkg/cli/validation_output.go (new file)
  • pkg/cli/validation_output_test.go (new file)

Files to Update

  • pkg/cli/compile_command.go
  • pkg/cli/run_command.go
  • pkg/cli/mcp_inspect_command.go
  • pkg/cli/audit_command.go
  • pkg/cli/compile_validation.go

Related Issues


💡 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.

Copilot AI and others added 2 commits January 30, 2026 04:38
…le formatting

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Integrate console formatting with validation errors Integrate console formatting with validation errors Jan 30, 2026
Copilot AI requested a review from pelikhan January 30, 2026 04:47
@pelikhan
Copy link
Contributor

@copilot show example of errors

Copy link
Contributor Author

Copilot AI commented Jan 30, 2026

@copilot show example of errors

Here are examples of the formatted validation errors:

Before/After Comparison

Before (plain text):

--purge flag can only be used when compiling all markdown files

After (with console formatting):

✗ --purge flag can only be used when compiling all markdown files

Real Examples

Example 1 - Flag validation:

$ gh aw compile --purge test-workflow
✗ --purge flag can only be used when compiling all markdown files (no specific files specified)

Example 2 - Incompatible flags:

$ gh aw compile --dependabot test.md
✗ --dependabot flag cannot be used with specific workflow files

Example 3 - Invalid path:

$ gh aw compile --dir /absolute/path
✗ --dir must be a relative path, got: /absolute/path

Example 4 - Complex parsing error:

$ gh aw compile /tmp/invalid-engine.md
✗ failed to parse workflow file: error: at '/engine': 'oneOf' failed, none matched
- at '/engine': value must be one of 'claude', 'codex', 'copilot', 'custom'
- at '/engine': got string, want object

Key Changes

  • All validation errors now have the ✗ symbol prefix (displayed in red in terminals)
  • Error content and structure fully preserved
  • Consistent with other CLI error messages that already use console formatting

@pelikhan pelikhan marked this pull request as ready for review January 30, 2026 06:11
@pelikhan pelikhan merged commit 3cb1d27 into main Jan 30, 2026
125 checks passed
@pelikhan pelikhan deleted the copilot/integrate-console-formatting-errors branch January 30, 2026 06:14
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.

[Code Quality] Integrate console formatting with validation errors

2 participants