- Change default package_path from internal/service to internal for wider applicability. - Add instruction to output a specific message if no files are found or path does not exist in Step 1.
1.8 KiB
1.8 KiB
| name | description | version | parameters | allowed_shell_commands | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| result-refactor | Convert traditional Go error handling to Result[T] monadic style | 1.0 |
|
|
Result[T] Refactoring Recipe
Overview
Refactors all error handling in the target package to use the new Result[T] pattern.
Execution Steps
Step 1: Discover files
Objective: Find every file that needs changing.
Instructions: Recursively scan {{.package_path}} for .go files containing if err != nil.
If no files are found or the path does not exist, output exactly: "No files found matching the criteria."
Expected output: A clean numbered list of full file paths (one per line).
Step 2: Refactor each file
Objective: Generate the updated code.
Instructions: For each file from Step 1:
- Read the full original content.
- Refactor it to use
Result[T]instead of naked errors (follow existing style, preserve comments). - Return ONLY the complete new file inside a
go code block (no explanations). **Expected output:** Onego block per file, clearly labelled with the filename.
Step 3: Apply or patch
Objective: Safely write changes or create reviewable output.
Instructions:
- If
dry_runis true → create a unified diff patch file for review. - If false → write the new files (backup originals as
.bak).
Expected output: Confirmation of what was written + full path to any patch file.
Final Summary
Give me a concise executive summary: number of files changed, any warnings or patterns you noticed, and your recommended next step.