Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 19, 2025

This PR replaces gopkg.in/yaml.v3 with github.com/goccy/go-yaml to provide precise YAML error location information and adds support for frontmatter line offset calculation to handle documents with multiple frontmatter entries.

Problem

Previously, YAML syntax errors in frontmatter would either:

  • Show imprecise locations extracted from string parsing of error messages
  • Display confusing 1,1 coordinates when location information was unavailable
  • Not account for the frontmatter's position within the document structure
  • Lack support for future multiple frontmatter entries

Solution

Enhanced YAML Error Parsing with Line Offset Support:
The implementation leverages goccy/go-yaml's native error message format by parsing the [line:column] pattern directly from error strings, with proper line offset calculation for frontmatter position.

// Before: Hardcoded frontmatter start position
ExtractYAMLError(err, 1) // Always assumed frontmatter at document start

// After: Dynamic frontmatter position support
ExtractYAMLError(err, frontmatterLineOffset) // Accounts for document structure

Improved Error Location Calculation:
Updated to use the formula yamlLine + frontmatterLineOffset - 1 to properly handle:

  • The leading --- line of frontmatter
  • Frontmatter positioned anywhere in the document
  • Future multiple frontmatter entries
  • 1-based YAML error line numbers relative to YAML content

Comprehensive Test Coverage:
Added extensive test suite covering 16+ different YAML syntax error scenarios with various frontmatter offset positions.

Key Changes

  • Added dependency: github.com/goccy/go-yaml@v1.18.0
  • Line offset parameter: ExtractYAMLError now accepts frontmatterLineOffset
  • Dynamic position calculation: Uses FrontmatterResult.FrontmatterStart from parser
  • Future-proof design: Supports multiple frontmatter entries in documents
  • Improved error context: Accounts for leading --- line in calculations
  • Updated test suite: All tests use correct offset calculations

Impact

Before:

✗ workflow.md:8:1: error: failed to parse frontmatter

After:

✗ workflow.md:3:1: error: frontmatter parsing failed: non-map value is specified
   1 | name: Test Workflow
>  2 | on push
       ^
   3 | permissions: read

The error now correctly points to line 3 where the syntax error occurs, properly accounting for the frontmatter's position in the document and the leading --- line. This enables accurate error reporting regardless of where frontmatter appears in the document.

Fixes #100.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits August 19, 2025 03:19
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [copilot] yaml syntax errors with location Implement goccy/go-yaml for precise YAML error locations Aug 19, 2025
@Copilot Copilot AI requested a review from pelikhan August 19, 2025 03:26
Copilot finished work on behalf of pelikhan August 19, 2025 03:26
@pelikhan
Copy link
Contributor

@copilot do not try to unwrap the goccy error, send it directly to the output.

This change addresses @pelikhan's feedback to not unwrap goccy errors
but send them directly to output. Instead of using reflection to extract
from goccy error structure, we now parse the [line:column] format directly
from the goccy error message string.

Benefits:
- More direct approach using goccy error messages as-is
- Eliminates complex reflection-based error extraction
- Provides precise location information (e.g., 6:10 instead of 1:1)
- Better error messages from goccy library

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 19, 2025

@copilot do not try to unwrap the goccy error, send it directly to the output.

Done. I've removed the error unwrapping logic and now parse the goccy error message format directly using the [line:column] pattern from the error string. This approach is more direct and provides precise location information (e.g., 6:10 instead of 1:1) while eliminating the complex reflection-based extraction.

The change is in commit 08d7228.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.contoso.com
    • Triggering command: /tmp/go-build531937087/b278/cli.test -test.testlogfile=/tmp/go-build531937087/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI changed the title Implement goccy/go-yaml for precise YAML error locations Implement goccy/go-yaml with direct message parsing for precise error locations Aug 19, 2025
Copilot finished work on behalf of pelikhan August 19, 2025 03:42
@pelikhan
Copy link
Contributor

@copilot add extensive test suite of frontmatter scripts with syntax errors

- Created comprehensive test suite for frontmatter YAML syntax errors
- Added 16 different syntax error scenarios with precise error location testing
- Includes boundary conditions, edge cases, and real-world error examples
- Tests goccy/go-yaml's native [line:column] error format parsing
- Validates error message formatting and console output integration
- Covers unicode content, deeply nested structures, and complex YAML errors
- Ensures precise error reporting for improved debugging experience

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 19, 2025

@copilot add extensive test suite of frontmatter scripts with syntax errors

Added comprehensive frontmatter syntax error test suite with 16+ different error scenarios, including:

  • YAML syntax errors (missing colons, brackets, indentation)
  • Invalid characters and escape sequences
  • Duplicate keys and complex nested structures
  • Boundary conditions and real-world examples
  • Unicode content and edge cases

The tests validate goccy/go-yaml's precise [line:column] error location reporting and console formatting integration. All tests pass with detailed error logging.

Added in commit 2f59753.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.contoso.com
    • Triggering command: /tmp/go-build112151627/b278/cli.test -test.testlogfile=/tmp/go-build112151627/b278/testlog.txt -test.paniconexit0 -test.timeout=5m0s (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI changed the title Implement goccy/go-yaml with direct message parsing for precise error locations Implement goccy/go-yaml with direct message parsing and extensive syntax error test suite Aug 19, 2025
Copilot finished work on behalf of pelikhan August 19, 2025 04:00
@pelikhan
Copy link
Contributor

@copilot make sure that error line numbers take into account the leading --- line of the frontmatter . It should take line offset as parameter as document may have multiple frontmatter entries in future versions.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 19, 2025

@copilot make sure that error line numbers take into account the leading --- line of the frontmatter . It should take line offset as parameter as document may have multiple frontmatter entries in futu...

Updated the ExtractYAMLError function to accept a frontmatterLineOffset parameter that properly accounts for the leading --- line of the frontmatter. The function now correctly calculates line numbers using the formula yamlLine + frontmatterLineOffset - 1 to handle the fact that YAML error line numbers are 1-based relative to the YAML content.

Key changes:

  • Function signature updated to ExtractYAMLError(err error, frontmatterLineOffset int)
  • Line calculation accounts for frontmatter position in document
  • Works with FrontmatterResult.FrontmatterStart from the parser
  • Supports future multiple frontmatter entries as requested

The error reporting now correctly shows line 3 for the syntax error in the frontmatter content, properly accounting for the document structure.

Implemented in commit a378062.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.contoso.com
    • Triggering command: /tmp/go-build384940425/b278/cli.test -test.testlogfile=/tmp/go-build384940425/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI changed the title Implement goccy/go-yaml with direct message parsing and extensive syntax error test suite Implement goccy/go-yaml with line offset support for frontmatter error reporting Aug 19, 2025
Copilot finished work on behalf of pelikhan August 19, 2025 04:37
@pelikhan pelikhan marked this pull request as ready for review August 19, 2025 04:43
…te expected output formatting in tests for consistency
Copy link
Contributor

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

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

@copilot do not try

@pelikhan pelikhan requested a review from dsyme August 19, 2025 05:19
@pelikhan
Copy link
Contributor

Bette yaml errors with error location

@pelikhan pelikhan merged commit 774a768 into main Aug 19, 2025
6 checks passed
@pelikhan pelikhan deleted the copilot/fix-100 branch August 19, 2025 05:29
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.

[copilot] yaml syntax errors with location
2 participants