fix(mcp): over-long reason gets VALIDATION_ERROR and a specific Swedish message (#1811)
* fix(mcp): over-long reason gets VALIDATION_ERROR and a specific Swedish message gnubok_reverse_journal_entry / gnubok_undo_sie_import cap `reason` at 500 characters, but exceeding it produced code UNKNOWN_ERROR with message_sv "Något gick fel. Försök igen." while the cause sat only in message_en. getStructuredError now infers VALIDATION_ERROR from the message and getErrorMessage maps it to "Motiveringen får vara högst 500 tecken.". Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(errors): pin the reason-length pattern to 500 and assert the envelope on undo_sie_import Review findings: the Swedish message hard-codes 500, so the pattern must match that limit only; the undo_sie_import 501-char test now asserts code and both localized messages like the reverse test does. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
158ef0f484
commit
d35c401c0c
@@ -35,6 +35,12 @@ describe('getStructuredError', () => {
|
||||
expect(result.remediation?.tool).toBe('gnubok_lock_period')
|
||||
})
|
||||
|
||||
it('maps an over-long reason to VALIDATION_ERROR with a specific Swedish message', () => {
|
||||
const result = getStructuredError(new Error('reason must be 500 characters or fewer'))
|
||||
expect(result.code).toBe('VALIDATION_ERROR')
|
||||
expect(result.message_sv).toBe('Motiveringen får vara högst 500 tecken.')
|
||||
})
|
||||
|
||||
it('infers PERIOD_HAS_UNBOOKED_TRANSACTIONS from Swedish lock-error message', () => {
|
||||
const result = getStructuredError(
|
||||
new Error('Kan inte låsa period: 3 affärstransaktion(er) saknar bokföring.')
|
||||
|
||||
@@ -98,6 +98,10 @@ const GENERIC_FALLBACK: Bilingual = { sv: 'Något gick fel. Försök igen.', en:
|
||||
|
||||
// Known error patterns → user-friendly Swedish messages
|
||||
const ERROR_PATTERN_MAP: [RegExp, string | null][] = [
|
||||
[
|
||||
/reason must be 500 characters or fewer/i,
|
||||
'Motiveringen får vara högst 500 tecken.',
|
||||
],
|
||||
[
|
||||
/locked\/closed fiscal period/i,
|
||||
'Perioden är låst. Verifikationen kan inte skapas i en stängd eller låst period.',
|
||||
|
||||
@@ -158,6 +158,7 @@ function inferCode(message: string): string | null {
|
||||
if (/Bokföringen är låst/i.test(message)) return 'PERIOD_LOCKED'
|
||||
if (/Transaction not found/i.test(message)) return 'NOT_FOUND'
|
||||
if (/Invoice not found/i.test(message)) return 'NOT_FOUND'
|
||||
if (/must be \d+ characters or fewer/i.test(message)) return 'VALIDATION_ERROR'
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user