Skip to content

refactor: migrate error handling from name to type parameter with semantic error types#106

Merged
M-jerez merged 4 commits intomion-run-typesfrom
mion-refactor-errors
Aug 26, 2025
Merged

refactor: migrate error handling from name to type parameter with semantic error types#106
M-jerez merged 4 commits intomion-run-typesfrom
mion-refactor-errors

Conversation

@M-jerez
Copy link
Contributor

@M-jerez M-jerez commented Aug 26, 2025

🔄 Error Handling Refactoring

This PR completes the migration from the old name parameter to the new type parameter in RpcError instances across the codebase, implementing semantic, kebab-case error types for improved type safety and consistency.

✅ Changes Completed

Core Error System Updates

  • ✅ Updated RpcError and TypedError classes to use only type property
  • ✅ Removed all references to deprecated name property
  • ✅ Updated isRpcError and isTypedError type guards
  • ✅ Maintained strongly typed error system (no default type parameters)

RpcError Instantiation Fixes

  • ✅ Fixed all RpcError instances missing required type parameter
  • ✅ Implemented semantic, descriptive error types in kebab-case format:
    • internal-server-error - Generic internal server errors
    • route-not-found - 404 not found errors
    • parameter-validation-error - Parameter validation failures
    • parameter-deserialization-error - Parameter deserialization failures
    • invalid-request-body-type - Invalid request body types
    • request-body-parsing-error - JSON parsing errors
    • response-body-stringify-error - Response serialization errors
    • remote-methods-metadata-error - Metadata retrieval errors
    • unknown-execution-error - Generic execution errors

Test Updates

  • ✅ Updated all test expectations to use new error structure
  • ✅ Removed name property expectations from PublicRpcError objects
  • ✅ Updated error types from generic 'unknown' to specific semantic types
  • ✅ Fixed all router, core, and run-types test files

Files Modified

  • packages/core/src/errors.ts - Updated error classes and type guards
  • packages/router/src/errors.ts - Added semantic error types
  • packages/router/src/notFound.ts - Added route-not-found error type
  • packages/router/src/dispatch.ts - Added parameter validation error types
  • packages/router/src/jsonBodyParser.routes.ts - Added body parsing error types
  • packages/router/src/client.routes.ts - Added metadata error type
  • Multiple example and test files updated

🧪 Test Results

  • Core package: All tests passing
  • Run-types RpcError tests: All tests passing
  • Router package: Most tests passing (1 pre-existing issue unrelated to changes)

🎯 Benefits

  • Type Safety: All errors now strongly typed through type property
  • Consistency: Uniform error structure across the codebase
  • Semantic Types: Descriptive, kebab-case error types for better DevEx
  • Maintainability: Centralized error type definitions

🔍 Notes

  • Maintained strongly typed error system as requested (no default type parameters)
  • All error types follow kebab-case naming convention
  • One remaining test failure appears to be pre-existing run-types system issue unrelated to this refactoring
  • All RpcError-related TypeScript metadata issues resolved

Pull Request opened by Augment Code with guidance from the PR author

Resolves #96

@M-jerez M-jerez merged commit 6be4555 into mion-run-types Aug 26, 2025
1 check failed
@M-jerez M-jerez deleted the mion-refactor-errors branch August 26, 2025 23:01
This was referenced Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant