[priority: high] Inconsistent error handling — mixed return-null/throw/false patterns with no error context #101
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Severity: High — callers can't predict error handling strategy; silent failures provide no debugging context.
Findings:
nullorfalseon failure (e.g.,convertManareturns boolean,unlockElementreturns boolean)crafting-equipment.tsusesthrow— inconsistent with the restfalseon failure with no error context (insufficient materials vs invalid effects vs capacity exceeded all produce samefalse)gameStore.ts tick()has no error boundary — a single store failure crashes the entire game loopAffected files:
src/lib/game/crafting-equipment.ts,src/lib/game/crafting-design.tssrc/lib/game/stores/manaStore.ts,src/lib/game/stores/gameStore.tssrc/lib/game/stores/craftingStore.tssrc/lib/game/stores/combat-actions.tssrc/lib/game/stores/prestigeStore.tsSuggested fix: Standardize on returning
{ success: boolean; error?: string }for expected failures. Reservethrowfor truly unexpected errors. Add try/catch totick(). Add persist migration/error handling for localStorage.Confidence: High
Dimension: error_consistency (score: 55.0%)
Starting work on issue #101 — standardizing error handling across the codebase. Plan:
Progress Report on Gitea Issue: Fix Error Handling Inconsistencies
✅ Completed Core Improvements
1. Standardized Result Type System
src/lib/game/utils/result.tswith unified error handling patternResult<T>type and error code constants for consistent failure reportingok(),fail(),unwrapOr(),isErrorCode()2. Mana Store Refactor
Result<T>with error context:convertMana()→ ReturnsResult<{ converted: number }>with specific error codesunlockElement()→ ReturnsResult<void>with failure reasonsspendElementMana()→ ReturnsResult<void>with detailed error contextcraftComposite()→ ReturnsResult<void>with ingredient-specific errors3. Crafting System Enhancements
throwwithResult<T>incompleteEquipmentCrafting()lastErrorfield and populated it on action failureslastError.codeandlastError.messagestartDesigningEnchantment,startApplying,startPreparing,startCraftingEquipmentErrorCode.ELEMENT_NOT_UNLOCKEDfor locked elementsErrorCode.INSUFFICIENT_CAPACITYfor design capacity issuesErrorCode.MISSING_MATERIALSfor insufficient crafting materials4. Game Loop Safety
try...catchblock ingameStore.tick()🔄 Remaining Tasks
1. Combat Actions Refactor
combat-actions.tsprocessCombatTick()functionCombatTickResulttoResult<CombatTickResult>would break all callers2. Prestige Store Refactor
prestigeStore.tsactions likedoPrestige(),startPactRital()3. LocalStorage Error Handling
persistmiddleware in all store files4. Test Updates
{ success: boolean, data|error, code?: string }pattern🎯 Impact Summary
Before Fix:
After Fix:
Result<T>pattern for critical operations📋 Recommended Next Steps
The core issue of inconsistent error handling has been substantially addressed. The codebase now has robust error boundaries and detailed error reporting, making it significantly more maintainable and debuggable.
Setting issue to in-progress and continuing with remaining tasks per comment 683: