Skip to content

[task] Add inline examples to schema validation errors #4074

@github-actions

Description

@github-actions

Objective

Enhance schema validation error messages to provide inline examples rather than just referencing the schema. When validation fails, show the user exactly what correct YAML should look like.

Context

Part of discussion #4071 - Repository Quality Improvement. Schema validation errors currently return generic messages that reference the schema but don't provide actionable examples. This forces users to search documentation.

Approach

  1. Enhance pkg/workflow/schema_validation.go to parse schema validation errors and identify which field failed
  2. Create a helper function extractFieldFromSchemaError() to parse JSON schema validation errors
  3. Build a map of common field examples for quick lookup
  4. Provide field-specific examples based on the failed field

Files to Modify

  • Update: pkg/workflow/schema_validation.go
  • Update: pkg/workflow/schema_validation_test.go
  • Create: Helper function for field extraction and example mapping

Example Improvements

Current behavior:

return fmt.Errorf("GitHub Actions schema validation failed: %w", err)

Improved behavior for timeout-minutes:

GitHub Actions schema validation failed for 'timeout-minutes': must be an integer. Example: timeout-minutes: 10

Improved behavior for engine:

GitHub Actions schema validation failed for 'engine': invalid value. Valid engines are: copilot, claude, codex, custom. Example: engine: copilot

Improved behavior for permissions:

GitHub Actions schema validation failed for 'permissions': must be an object with permission levels. Example: permissions:\\n  contents: read\\n  issues: write

Implementation Steps

  1. Add helper function to extract field name from schema validation error message
  2. Create map of field-specific examples for common fields:
    • timeout-minutes, engine, permissions, on, tools, etc.
  3. Enhance validateGitHubActionsSchema() to parse the error and provide targeted examples
  4. Add comprehensive tests for different schema validation failure scenarios

Acceptance Criteria

  • Schema validation errors extract field name from validation error
  • Field-specific examples are provided based on the failed field
  • Common schema violations (type mismatches, missing fields) have tailored examples
  • Error messages reference both the schema issue and provide inline examples
  • Tests verify example inclusion in schema validation errors
  • Handle cases where field name cannot be extracted (fallback to generic message)
  • Run make test-unit to verify all tests pass

AI generated by Plan Command for discussion #4071

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions