Skip to content

Comments

fix(parser): report all safe-output schema failures with per-field line/column locations#17524

Merged
pelikhan merged 4 commits intomainfrom
copilot/add-more-testing
Feb 21, 2026
Merged

fix(parser): report all safe-output schema failures with per-field line/column locations#17524
pelikhan merged 4 commits intomainfrom
copilot/add-more-testing

Conversation

Copy link
Contributor

Copilot AI commented Feb 21, 2026

Original prompt

Create a pr that has the changes in #17484

Add more testing


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…res with additional tests

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add more tests to improve code coverage fix(parser): report all safe-output schema failures with per-field line/column locations Feb 21, 2026
@pelikhan pelikhan marked this pull request as ready for review February 21, 2026 16:38
Copilot AI review requested due to automatic review settings February 21, 2026 16:38
@pelikhan
Copy link
Contributor

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request improves schema validation error reporting for safe-outputs frontmatter by ensuring all validation failures are reported with their respective line and column locations, rather than only reporting the first failure.

Changes:

  • Modified validateWithSchemaAndLocation to aggregate all schema failures and include per-field location details
  • Added formatSchemaFailureDetail helper function to format individual failure details with path and location
  • Added comprehensive test coverage for multiple failures, empty path normalization, and single vs. multiple failure formatting

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/parser/schema_compiler.go Implements aggregated error reporting with location details for all failures; adds formatSchemaFailureDetail helper
pkg/parser/safe_outputs_error_location_test.go Adds four new tests covering multiple failures, empty path handling, line/column formatting, and single failure behavior
Comments suppressed due to low confidence (2)

pkg/parser/schema_compiler.go:307

  • When the primary error path's location cannot be found in the YAML (location.Found is false), the code falls through to the fallback case and discards all the detail lines that were just created for multiple errors. This means that if we have multiple schema failures but the first one's location cannot be determined, we fall back to showing only a single error message instead of reporting all failures as intended.

Consider either: (1) using the detail lines even when location.Found is false, with a default position, or (2) iterating through jsonPaths to find the first one with a locatable position to use as the primary path.

			if location.Found {
				// Adjust line number to account for frontmatter position in file
				adjustedLine := location.Line + frontmatterStart - 1

				// Create context lines around the adjusted line number in the full file
				var adjustedContextLines []string
				if filePath != "" {
					// Use the same sanitized path
					if content, readErr := os.ReadFile(cleanPath); readErr == nil {
						allLines := strings.Split(string(content), "\n")
						// Create context around the adjusted line (±3 lines)
						// The console formatter expects context to be centered around the error line
						contextSize := 7                                     // ±3 lines around the error
						contextStart := max(0, adjustedLine-contextSize/2-1) // -1 for 0-based indexing
						contextEnd := min(len(allLines), contextStart+contextSize)

						for i := contextStart; i < contextEnd; i++ {
							adjustedContextLines = append(adjustedContextLines, allLines[i])
						}
					}
				}

				// If we couldn't create adjusted context, fall back to frontmatter context
				if len(adjustedContextLines) == 0 {
					adjustedContextLines = contextLines
				}

				// Include every schema failure with path + line + column.
				message := ""
				if len(detailLines) == 1 {
					message = detailLines[0]
				} else {
					message = "Multiple schema validation failures:\n- " + strings.Join(detailLines, "\n- ")
				}

				// Create a compiler error with precise location information
				compilerErr := console.CompilerError{
					Position: console.ErrorPosition{
						File:   filePath,
						Line:   adjustedLine,
						Column: location.Column, // Use original column, we'll extend to word in console rendering
					},
					Type:    "error",
					Message: message,
					Context: adjustedContextLines,
					// Hints removed as per requirements
				}

				// Format and return the error
				formattedErr := console.FormatError(compilerErr)
				return errors.New(formattedErr)
			}

pkg/parser/safe_outputs_error_location_test.go:440

  • The word "normalised" should be changed to "normalized" to match the American English spelling convention used consistently throughout the rest of the codebase.
// TestFormatSchemaFailureDetailEmptyPath verifies that an empty path is normalised to "/".

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor Author

Copilot AI commented Feb 21, 2026

@copilot merge main, fix tests in https://github.com/github/gh-aw/actions/runs/22260319728/job/64397617808#step:10:1

Done in 7971531. Merged main and fixed TestStrictModeDeprecatedFieldErrorMessage — the root cause was that formatSchemaFailureDetail wasn't passing schemaJSON through to generateSchemaBasedSuggestions, so the "Did you mean 'timeout-minutes'?" suggestion was no longer appended to the error message. Added schemaJSON as a parameter to the helper and restored the suggestions call.

@pelikhan pelikhan merged commit c9eeff5 into main Feb 21, 2026
34 checks passed
@pelikhan pelikhan deleted the copilot/add-more-testing branch February 21, 2026 16:50
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.

2 participants