refactor: update return types and error handling across various use cases#1807
Conversation
…ases - Updated `findTableSettingsOrReturnEmpty` to return a more specific type. - Changed middleware configuration methods to return `void` instead of `any`. - Enhanced error handling in multiple use cases by utilizing `getErrorMessage` for consistent error messages. - Improved type safety in helper functions and entities. - Added type definitions for Express request to include decoded Cognito data. - Adjusted TypeScript configuration to extend from `tsconfig.src.json`.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR systematically improves TypeScript type safety across the codebase by replacing loose ChangesType Safety and Error Handling Standardization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR refactors backend TypeScript typing and error-message handling to reduce any usage, centralize caught-error formatting, and align build/type-checking behavior with stricter source settings.
Changes:
- Replaces many
(error as Error).messageusages withgetErrorMessage(...). - Tightens return types, helper signatures, middleware
nexttyping, and request typings. - Adds Express request augmentation for Cognito data and updates build config to extend stricter source config.
Reviewed changes
Copilot reviewed 81 out of 82 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
backend/tsconfig.build.json |
Builds now extend tsconfig.src.json. |
backend/src/types/express.d.ts |
Adds Express Request.decoded augmentation. |
backend/src/helpers/validators/is-action-url-host-allowed.ts |
Uses shared error-message helper. |
backend/src/helpers/slack/slack-post-message.ts |
Narrows Slack return type to unknown. |
backend/src/helpers/is-object-empty.ts |
Narrows helper input type. |
backend/src/helpers/get-property-value-by-descriptor.ts |
Narrows object/value types and handles missing descriptors. |
backend/src/helpers/enum-to-string.ts |
Adds generic enum-like constraint. |
backend/src/helpers/compare-array-elements.ts |
Adds generic readonly array typing. |
backend/src/exceptions/all-exceptions.filter.ts |
Handles unknown exceptions with typed metadata extraction. |
backend/src/entities/logging/winston-logger.ts |
Formats unknown log messages before logging/slack posting. |
backend/src/authorization/cognito-decoded.interface.ts |
Narrows request query/params and documents Cognito request type. |
backend/src/authorization/*.middleware.ts |
Uses Express NextFunction. |
backend/src/decorators/*.ts |
Replaces decorator data any with unknown. |
backend/src/entities/**/*.module.ts |
Changes Nest module configure return types to void. |
backend/src/entities/**/*use*.ts |
Standardizes caught-error message extraction. |
backend/src/entities/**/*service.ts |
Standardizes caught-error message extraction. |
backend/src/entities/**/*entity.ts |
Standardizes JSON parse/stringify error logging. |
backend/src/entities/table/utils/process-found-rows-util.ts |
Coerces descriptor values to strings for template replacement. |
backend/src/entities/table-settings/**/repository/* |
Narrows table-settings repository return type. |
backend/src/entities/*/controller.ts |
Narrows controller method return types. |
backend/src/entities/table-schema/**/*.ts |
Standardizes validation/tooling error messages. |
backend/src/entities/connection/**/*.ts |
Standardizes DDL/diagram error messages. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return message.stack ?? message.message; | ||
| } | ||
| try { | ||
| return JSON.stringify(message); |
| } | ||
| } catch (err) { | ||
| const message = (err as Error).message ?? 'validation error'; | ||
| const message = getErrorMessage(err) ?? 'validation error'; |
findTableSettingsOrReturnEmptyto return a more specific type.voidinstead ofany.getErrorMessagefor consistent error messages.tsconfig.src.json.Summary by CodeRabbit
Bug Fixes
Refactor