fix: Handle duplicate series name error on rename instead of crashing

PATCH /api/series/:id with a name that already exists in the same library
causes an unhandled SequelizeUniqueConstraintError that crashes the server
process (exit code 1). Wrap the save() call in try/catch and return 400.

The included test "should return 400 when renaming to a name that already
exists in the same library" also serves as a minimal reproducer for the bug:
run it against the unpatched SeriesController and it throws the unhandled
SequelizeUniqueConstraintError (the same error seen in production as a fatal
unhandled rejection at SeriesController.js:83).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
D. Rimron-Soutter 2026-03-11 13:57:00 +00:00
parent fbe1d1eed6
commit b58ddaf9d3
2 changed files with 194 additions and 1 deletions

View file

@ -80,7 +80,15 @@ class SeriesController {
}
req.series.set(payload)
if (req.series.changed()) {
await req.series.save()
try {
await req.series.save()
} catch (error) {
if (error.name === 'SequelizeUniqueConstraintError') {
Logger.warn(`[SeriesController] Series name already exists in library: ${payload.name}`)
return res.status(400).send('A series with that name already exists in this library')
}
throw error
}
SocketAuthority.emitter('series_updated', req.series.toOldJSON())
}
res.json(req.series.toOldJSON())