|
| 1 | +# /autofix - Debug FactorioAccess crashes from manual gameplay |
| 2 | + |
| 3 | +This command helps you debug crashes and issues that users experience while playing Factorio manually. |
| 4 | + |
| 5 | +## What this does |
| 6 | + |
| 7 | +When a user reports a crash or issue from their manual Factorio gameplay, this command: |
| 8 | +1. Immediately captures all relevant logs before they're lost |
| 9 | +2. Analyzes the crash to identify the root cause |
| 10 | +3. Helps you fix small issues (<50 lines) immediately |
| 11 | +4. Guides you through the debugging workflow |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +Just say: `/autofix` |
| 16 | + |
| 17 | +## What happens next |
| 18 | + |
| 19 | +1. I'll check important file paths using `python3 launch_factorio.py --show-paths` |
| 20 | +2. I'll immediately run `python3 launch_factorio.py --capture-logs` to save the logs |
| 21 | +3. **CRITICAL REQUIREMENT**: |
| 22 | + - If the launcher returns empty/null logs, I MUST STOP IMMEDIATELY |
| 23 | + - I will NOT proceed without logs - it's a waste of everyone's time |
| 24 | + - I will ask for help to locate the logs instead of guessing or continuing blindly |
| 25 | + - The launcher should fail hard if logs can't be found |
| 26 | +4. I'll analyze the captured logs for any crash or error information |
| 27 | +5. If a bug is found: |
| 28 | + - I'll show you the relevant error information |
| 29 | + - I'll guide you through the fix process |
| 30 | + - **CRITICAL**: I'll use MessageBuilder for ALL string concatenation with LocalisedStrings |
| 31 | + - I'll format the code and commit the changes |
| 32 | + - I'll help you test the fix before the user tries again |
| 33 | +6. If no bug is found but logs were captured: |
| 34 | + - I'll report that no crash was detected in the logs |
| 35 | + - I'll ask you to describe what issue you encountered |
| 36 | + - I'll then proceed to help debug based on your description |
| 37 | + |
| 38 | +## Important notes |
| 39 | + |
| 40 | +- Act quickly! Logs are overwritten when Factorio restarts |
| 41 | +- The user is playing manually, not through the launcher |
| 42 | +- Focus on being helpful and responsive to keep the user engaged |
| 43 | +- Always format your changes before asking the user to retry |
| 44 | +- ALWAYS commit your changes after fixing bugs or adding features |
| 45 | +- Unit tests cannot be run while the user has Factorio open - rely on formatting and linting only |
| 46 | +- **NEVER run tests during debugging** - they overwrite the printout log! |
| 47 | +- If you can't find the issue after examining logs, ask the user for help instead of flailing |
| 48 | +- The launcher now captures factorio-access-printout.log which contains all speech output |
| 49 | +- Users will continue in the same session, providing more bugs as followups without rerunning this command. |
| 50 | + |
| 51 | +## CRITICAL: Localization and String Handling |
| 52 | + |
| 53 | +**ALWAYS USE MessageBuilder FOR LOCALIZATION!** Never concatenate LocalisedStrings with regular strings using `..` |
| 54 | + |
| 55 | +### Common Localization Errors to Avoid: |
| 56 | + |
| 57 | +1. **WRONG**: String concatenation with LocalisedStrings |
| 58 | + ```lua |
| 59 | + -- This will crash! |
| 60 | + local result = "Power: " .. get_power_string(power) .. " capacity" |
| 61 | + ``` |
| 62 | + |
| 63 | +2. **WRONG**: Mixed table concatenation |
| 64 | + ```lua |
| 65 | + -- This will also crash! |
| 66 | + local result = {"", "Power: ", get_power_string(power), " capacity"} |
| 67 | + ``` |
| 68 | + |
| 69 | +3. **CORRECT**: Use MessageBuilder |
| 70 | + ```lua |
| 71 | + local message = MessageBuilder.new() |
| 72 | + message:fragment("Power: ") |
| 73 | + message:fragment(get_power_string(power)) |
| 74 | + message:fragment(" capacity") |
| 75 | + printout(message:build(), pindex) |
| 76 | + ``` |
| 77 | + |
| 78 | +### MessageBuilder Pattern: |
| 79 | +- Always `require("scripts.message-builder")` at the top of files |
| 80 | +- Create new instance with `MessageBuilder.new()` |
| 81 | +- Add fragments with `message:fragment(text_or_localised_string)` |
| 82 | +- Build final message with `message:build()` |
| 83 | +- MessageBuilder properly handles mixing LocalisedStrings and regular strings |
| 84 | + |
| 85 | +### Direction Localization: |
| 86 | +- Use `{"fa.direction", direction_number}` not `"fa.direction-" .. direction_name` |
| 87 | +- Direction numbers: 0=North, 4=East, 8=South, 12=West, etc. |
| 88 | +- ***IMPORTANT**: use defines.north etc. instead in all applicable locations. |
| 89 | + |
| 90 | +## Related documentation |
| 91 | + |
| 92 | +See `llm-docs/debugging-manual-runs.md` for the full debugging guide. |
0 commit comments