Skip to content

Commit d6e4e43

Browse files
committed
fix(validation): defensive null check in Zod error formatting
1 parent bfef398 commit d6e4e43

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
All notable changes to this project are documented in this file.
44

5+
## [v0.8.1] - 2026-01-07
6+
7+
### fix
8+
9+
- **Validation**: Fixed crash in Zod error formatting middleware
10+
- Added defensive null check in `formatZodErrors` function
11+
- Handle cases where `error.errors` is undefined by falling back to `error.issues`
12+
- Added safe property access with optional chaining to prevent unhandled rejections
13+
- Prevents server crash when validation errors have unexpected structure
14+
515
## [v0.8.0] - 2026-01-03
616

717
### feat

middleware/validation/index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@ const formatZodErrors = (error) => {
1515
return { message: 'Validation error', errors: [] };
1616
}
1717

18-
const errors = error.errors.map(err => ({
19-
field: err.path.join('.'),
20-
message: err.message,
21-
code: err.code,
18+
// Defensive check for error.errors being undefined or not an array
19+
const zodErrors = error.errors || error.issues || [];
20+
if (!Array.isArray(zodErrors)) {
21+
return {
22+
message: error.message || 'Validation failed',
23+
errors: []
24+
};
25+
}
26+
27+
const errors = zodErrors.map(err => ({
28+
field: err.path?.join('.') || '',
29+
message: err.message || 'Invalid value',
30+
code: err.code || 'validation_error',
2231
}));
2332

2433
// Create a summary message from the first few errors

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "finx",
3-
"version": "0.8.0",
3+
"version": "0.8.1",
44
"description": "A modern personal finance management application",
55
"main": "server.js",
66
"scripts": {

0 commit comments

Comments
 (0)