refactor: simplify error handling patterns - replace custom error classes with standard Error() #1305
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Simplifies error handling by replacing custom error classes with standard
Error()
+ descriptive messages and context objects, reducing code complexity while maintaining clear error reporting.Changes
Removed Custom Error Classes
Eliminated two custom error classes in
src/modules/diet/macro-target/application/macroTarget.ts
:WeightNotFoundForDayError
(26 lines)MacroTargetNotFoundForDayError
(26 lines)These classes primarily added type complexity without runtime benefits. Their constructors, custom properties, and
toJSON()
methods are no longer needed.New Pattern: Standard Error with Context
Before:
After:
Documentation Updates
Updated
docs/CODESTYLE_GUIDE.md
to reflect the new standard:Error()
withcause
propertycause
property with relevant data (IDs, operation names)Benefits
cause
propertyTesting
✅ All 368 tests passing
✅ Type checking passes
✅ Error handling infrastructure (
showError
) preserved and working✅ Error messages remain descriptive and contextual
✅ No regression in user error experience
Rationale
This refactoring aligns with the project's frontend simplicity principles:
Error()
+ good error handling functions are sufficientCloses #[issue-number]
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/marcuscastelo/macroflows/branches
curl -s REDACTED
(http block)https://api.github.com/repos/marcuscastelo/macroflows/compare/9a60ac53dfc707e5e0f49cd6cdaa3937d6a46fbf...fb134a2685842b898c47efcd934f8b89d957870f
curl -s -w \n%{http_code} -D /tmp/semver_headers_4013.txt REDACTED
(http block)test.supabase.co
node (vitest 1)
(dns block)node (vitest 3)
(dns block)node (vitest 2)
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.