[PR #2547] [MERGED] fix(import): surface real error instead of 500 when character import throws #5648

Closed
opened 2026-10-22 04:18:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2547
Author: @Gunterlie
Created: 6/12/2026
Status: ✅ Merged
Merged: 6/13/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/import-unhandled-500


📝 Commits (1)

  • 48944f8 fix(import): surface real error instead of 500 when character import throws

📊 Changes

2 files changed (+29 additions, -14 deletions)

View changed files

📝 packages/server/src/routes/import.routes.ts (+26 -13)
📝 packages/server/src/services/import/st-character.importer.ts (+3 -1)

📄 Description

Problem

importSTCharacter was called without a try/catch in three places inside the import route:

  • JSON body path (POST /import/st-character from bot browser / JSON card drop)
  • PNG buffer path (importCharacterBuffer for .png uploads)
  • JSON buffer path (importCharacterBuffer for .json uploads)

Any uncaught exception — most commonly the embedded lorebook rollback failure — escaped to Fastify's global error handler, which returned a generic HTTP 500 { error: "Internal Server Error" }. The client displayed this as an opaque toast with no actionable information.

The JSON buffer path had a try/catch but it wrapped both JSON.parse and importSTCharacter together, so real import errors were swallowed and reported as "Invalid file format" — also wrong.

Fix

  • Wrap all three importSTCharacter call sites so failures return { success: false, error } with the actual error message (or String(err) if the thrown value isn't an Error object).
  • Split the JSON buffer path try/catch so parse errors and import errors are reported separately with accurate messages.
  • Improve the embedded lorebook rollback error message from internal jargon ("failed without a lorebook ID") to a user-facing message.

Test plan

  • Import a character card from bot browser (JannyAI or similar) — success case still works
  • Import a PNG character card — success case still works
  • Import a JSON character card — success case still works
  • Trigger a lorebook rollback failure (e.g. corrupt character_book) — toast now shows the actual error instead of "Internal Server Error"
  • Upload a non-character JSON file — still shows "Invalid file format"

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/2547 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 6/12/2026 **Status:** ✅ Merged **Merged:** 6/13/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/import-unhandled-500` --- ### 📝 Commits (1) - [`48944f8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/48944f8c83a3571d0e695529dd5f3eeff3b4833b) fix(import): surface real error instead of 500 when character import throws ### 📊 Changes **2 files changed** (+29 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/import.routes.ts` (+26 -13) 📝 `packages/server/src/services/import/st-character.importer.ts` (+3 -1) </details> ### 📄 Description ## Problem `importSTCharacter` was called without a `try/catch` in three places inside the import route: - JSON body path (`POST /import/st-character` from bot browser / JSON card drop) - PNG buffer path (`importCharacterBuffer` for `.png` uploads) - JSON buffer path (`importCharacterBuffer` for `.json` uploads) Any uncaught exception — most commonly the embedded lorebook rollback failure — escaped to Fastify's global error handler, which returned a generic HTTP 500 `{ error: "Internal Server Error" }`. The client displayed this as an opaque toast with no actionable information. The JSON buffer path had a `try/catch` but it wrapped both `JSON.parse` and `importSTCharacter` together, so real import errors were swallowed and reported as "Invalid file format" — also wrong. ## Fix - Wrap all three `importSTCharacter` call sites so failures return `{ success: false, error }` with the actual error message (or `String(err)` if the thrown value isn't an `Error` object). - Split the JSON buffer path `try/catch` so parse errors and import errors are reported separately with accurate messages. - Improve the embedded lorebook rollback error message from internal jargon ("failed without a lorebook ID") to a user-facing message. ## Test plan - [ ] Import a character card from bot browser (JannyAI or similar) — success case still works - [ ] Import a PNG character card — success case still works - [ ] Import a JSON character card — success case still works - [ ] Trigger a lorebook rollback failure (e.g. corrupt character_book) — toast now shows the actual error instead of "Internal Server Error" - [ ] Upload a non-character JSON file — still shows "Invalid file format" 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:18:07 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5648
No description provided.