From 8bd1242156872eeada67300086a60af57b43b422 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 13:48:56 +0000 Subject: [PATCH 1/2] Initial plan From 25c17654023e1eaeb8deeca17767f3798a12de10 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 14:00:06 +0000 Subject: [PATCH 2/2] fix: prevent double-format wrapping for pre-formatted compiler errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - pkg/parser/schema_compiler.go: return &FormattedParserError{} instead of errors.New() so isFormattedCompilerError() recognises them and compiler.go does not re-wrap with a spurious file:1:1: error: prefix - pkg/parser/import_error.go: add NewFormattedParserError constructor for external packages to create FormattedParserError values - pkg/workflow/frontmatter_error.go: return parser.NewFormattedParserError() for pre-formatted YAML error strings instead of fmt.Errorf() - pkg/workflow/compiler_error_formatter_test.go: cover NewFormattedParserError path Fixes # — compiler error messages double-format with wrong line number Agent-Logs-Url: https://github.com/github/gh-aw/sessions/a25ffcf4-a170-4618-8c25-3837826bef98 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- pkg/parser/import_error.go | 7 +++++++ pkg/parser/schema_compiler.go | 4 ++-- pkg/workflow/compiler_error_formatter_test.go | 5 +++++ pkg/workflow/frontmatter_error.go | 4 ++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/parser/import_error.go b/pkg/parser/import_error.go index ad3e1edbe4a..62e596aec5b 100644 --- a/pkg/parser/import_error.go +++ b/pkg/parser/import_error.go @@ -84,6 +84,13 @@ type FormattedParserError struct { func (e *FormattedParserError) Error() string { return e.formatted } func (e *FormattedParserError) Unwrap() error { return e.cause } +// NewFormattedParserError creates a FormattedParserError with the given pre-formatted +// message string. Use this in external packages (e.g. pkg/workflow) to return an error +// that isFormattedCompilerError can detect without double-wrapping. +func NewFormattedParserError(formatted string) *FormattedParserError { + return &FormattedParserError{formatted: formatted} +} + // FormatImportError formats an import error as a compilation error with source location func FormatImportError(err *ImportError, yamlContent string) error { importErrorLog.Printf("Formatting import error: path=%s, file=%s, line=%d", err.ImportPath, err.FilePath, err.Line) diff --git a/pkg/parser/schema_compiler.go b/pkg/parser/schema_compiler.go index fb18aa7b048..96ced941deb 100644 --- a/pkg/parser/schema_compiler.go +++ b/pkg/parser/schema_compiler.go @@ -354,7 +354,7 @@ func validateWithSchemaAndLocation(frontmatter map[string]any, schemaJSON, conte // Format and return the error formattedErr := console.FormatError(compilerErr) - return errors.New(formattedErr) + return &FormattedParserError{formatted: formattedErr} } } @@ -382,7 +382,7 @@ func validateWithSchemaAndLocation(frontmatter map[string]any, schemaJSON, conte // Format and return the error formattedErr := console.FormatError(compilerErr) - return errors.New(formattedErr) + return &FormattedParserError{formatted: formattedErr} } // Fallback to the original error if we can't format it nicely diff --git a/pkg/workflow/compiler_error_formatter_test.go b/pkg/workflow/compiler_error_formatter_test.go index d1277af54e0..d631ee16da9 100644 --- a/pkg/workflow/compiler_error_formatter_test.go +++ b/pkg/workflow/compiler_error_formatter_test.go @@ -45,6 +45,11 @@ func TestIsFormattedCompilerError(t *testing.T) { }, "imports:\n - missing.md"), expected: true, }, + { + name: "error from parser.NewFormattedParserError is detected as formatted", + err: parser.NewFormattedParserError("workflow.md:5:3: error: bad value"), + expected: true, + }, { name: "plain error is not formatted", err: errors.New("plain error"), diff --git a/pkg/workflow/frontmatter_error.go b/pkg/workflow/frontmatter_error.go index 2d90c92a35d..076046d12b7 100644 --- a/pkg/workflow/frontmatter_error.go +++ b/pkg/workflow/frontmatter_error.go @@ -73,11 +73,11 @@ func (c *Compiler) createFrontmatterError(filePath, content string, err error, f context := errorStr[loc[0]+1:] // +1 to skip the leading newline // Return VSCode-compatible format on first line, followed by source context only frontmatterErrorLog.Print("Formatting error for VSCode compatibility") - return fmt.Errorf("%s\n%s", vscodeFormat, context) + return parser.NewFormattedParserError(fmt.Sprintf("%s\n%s", vscodeFormat, context)) } // If we can't extract source context, return just the VSCode format - return fmt.Errorf("%s", vscodeFormat) + return parser.NewFormattedParserError(vscodeFormat) } // Fallback if we can't parse the line/col