Enhance error messages in compiler.go with examples#4096
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot continue work |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Completed! I've enhanced all user-facing error messages in compiler.go with actionable examples. What was improved:
Key results:
Example of improvement: Before: After: The error messages now provide:
Commits: 734aefe (frontmatter + file size), 0bee085 (reaction + command) |
|
@copilot lint |
There was a problem hiding this comment.
Pull Request Overview
This PR successfully enhances user-facing error messages in pkg/workflow/compiler.go by adding actionable examples that demonstrate correct syntax. The changes transform cryptic error messages into helpful guidance that shows users exactly how to fix compilation issues.
Key changes:
- Enhanced 4 direct error messages with concrete examples and explanations
- Added comprehensive test coverage to verify error message quality
- Maintained consistency with existing error formatting patterns using newline-separated examples
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| pkg/workflow/compiler_error_examples_test.go | New test file validating that error messages include examples and are sufficiently descriptive |
| pkg/workflow/compiler.go | Enhanced 4 error messages (frontmatter, markdown content, file size, reaction validation, command conflicts) with actionable examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| if result.Markdown == "" { | ||
| return nil, fmt.Errorf("no markdown content found") | ||
| return nil, fmt.Errorf("no markdown content found. Workflow files must include markdown content after the frontmatter. Example:\n---\non: issues\n---\n\n# Your workflow title\n\nWorkflow instructions here.") |
There was a problem hiding this comment.
The error message on line 640 is very long (over 180 characters). Consider using a multiline string literal for better code readability and maintainability.
| return nil, fmt.Errorf("no markdown content found. Workflow files must include markdown content after the frontmatter. Example:\n---\non: issues\n---\n\n# Your workflow title\n\nWorkflow instructions here.") | |
| return nil, fmt.Errorf(`no markdown content found. Workflow files must include markdown content after the frontmatter. Example: | |
| --- | |
| on: issues | |
| --- | |
| # Your workflow title | |
| Workflow instructions here.`) |
| // Validate reaction value | ||
| if !isValidReaction(reactionStr) { | ||
| return fmt.Errorf("invalid reaction value '%s': must be one of %v", reactionStr, getValidReactions()) | ||
| return fmt.Errorf("invalid reaction value '%s': must be one of %v. Example:\n---\non:\n issues:\n types: [opened]\n reaction: rocket\n---", reactionStr, getValidReactions()) |
There was a problem hiding this comment.
The error message on line 1268 is very long (over 180 characters). Consider using a multiline string literal or constructing the message in parts for better code readability and maintainability.
| return fmt.Errorf("invalid reaction value '%s': must be one of %v. Example:\n---\non:\n issues:\n types: [opened]\n reaction: rocket\n---", reactionStr, getValidReactions()) | |
| return fmt.Errorf( | |
| `invalid reaction value '%s': must be one of %v. | |
| Example: | |
| --- | |
| on: | |
| issues: | |
| types: [opened] | |
| reaction: rocket | |
| ---`, | |
| reactionStr, getValidReactions(), | |
| ) |
| for _, eventName := range conflictingEvents { | ||
| if _, hasConflict := onMap[eventName]; hasConflict { | ||
| return fmt.Errorf("cannot use 'command' with '%s' in the same workflow", eventName) | ||
| return fmt.Errorf("cannot use 'command' with '%s' in the same workflow. Command triggers use /mention syntax and are incompatible with event-based triggers. Example:\n---\non:\n command:\n name: bot-name\n---", eventName) |
There was a problem hiding this comment.
The error message on line 1286 is very long (over 220 characters). Consider using a multiline string literal for better code readability and maintainability.
| return fmt.Errorf("cannot use 'command' with '%s' in the same workflow. Command triggers use /mention syntax and are incompatible with event-based triggers. Example:\n---\non:\n command:\n name: bot-name\n---", eventName) | |
| return fmt.Errorf(`cannot use 'command' with '%s' in the same workflow. Command triggers use /mention syntax and are incompatible with event-based triggers. Example: |
Task: Add Examples to compiler.go Error Messages
Successfully enhanced all user-facing error messages in
pkg/workflow/compiler.gowith actionable examples. The improvements make compilation errors significantly more helpful by showing users exactly what correct syntax looks like.Changes Made
Frontmatter Errors (compiler.go lines 636-641)
File Size Error (compiler.go line 581)
Reaction Validation Error (compiler.go line 1268)
Command Conflict Error (compiler.go line 1286)
Test Coverage (compiler_error_examples_test.go)
Statistics
%w) - properly delegate to underlying errorsBefore & After Example
Before:
After:
Key Findings
fmt.Errorf("failed to X: %w", err))Test Results
✅ All tests passing (8.6s runtime)
✅ Build successful
✅ Error messages now include actionable examples
✅ TestErrorMessageQuality validates error message patterns
✅ 100% coverage of direct error messages in compiler.go
The error messages now provide:
Related to #4085
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.