fix(import): treat a voucher-less SIE file as a no-op, not a failed migration (#1445)

* fix(import): treat a voucher-less SIE file as a no-op, not a failed migration

A Fortnox migration aborted with the generic "Något gick fel. Försök
igen." when the current fiscal year had nothing booked yet: Fortnox
exports an empty SIE file for such a year, the finalizer's 0-entry
safety net flipped it to 'failed', and the wizard stopped before the
customer/supplier/invoice phase ever ran.

Three layered fixes:

- finalizeImportRecord only downgrades a 0-entry run to 'failed' when
  the file actually contained vouchers (parsed count via the
  documentation object). A file with no vouchers completes as a no-op
  with an explanatory warning; the mapping-fix retry loop the downgrade
  exists for (Lookma case) is unchanged.
- The migration wizard no longer routes messages that are already
  user-facing Swedish (server envelopes, ImportResult.errors) through
  getErrorMessage's Swedish-pattern heuristic, which swallowed
  unrecognized sentences into the generic fallback.
- The heuristic itself learns the import-error family
  (verifikation/importera) so other surfaces rethrowing engine
  messages keep the real reason too.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(import): cross-check raw #VER before accepting a 0-voucher file as empty

The parsed voucher count alone cannot prove a fiscal year was empty: a
field-separator or encoding mismatch can swallow every #VER block with
only a warning-severity parse issue, and executeSIEImport does not fail
on those. Only a raw content check proves the file never declared any
vouchers. Addresses the truncation/corruption finding from the Swedish
compliance review on #1445.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* docs: record the raw #VER safeguard in the empty-SIE-file decision entry

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-08-07 09:45:29 +02:00
committed by GitHub
co-authored by Claude Fable 5 Jakob Wennberg
parent 707d597b2e
commit 63d520719a
7 changed files with 199 additions and 14 deletions
@@ -460,6 +460,19 @@ describe('getErrorMessage: Swedish heuristic covers real route sentences', () =>
'Ett oväntat serverfel uppstod. Försök igen senare.',
)
})
// The CashLeads Fortnox migration (2026-08-06): the sie-import finalizer's
// guard message reached the wizard as a thrown Error, matched none of the
// patterns, and the user saw the generic fallback instead of the reason the
// migration stopped. Pins the added patterns: verifikation / importen.
it('the 0-verifikationer import guard sentence passes through verbatim', () => {
const thrown = new Error(
'Importen skapade 0 verifikationer: markerar som misslyckad så filen kan importeras om utan replace/undo. Granska varningarna för att se vilka konton som behöver mappas.',
)
const msg = getErrorMessage(thrown)
expect(msg).toContain('0 verifikationer')
expect(msg).not.toBe('Något gick fel. Försök igen.')
})
})
describe('getErrorMessage: GoTrue auth error patterns', () => {
+2
View File
@@ -210,6 +210,8 @@ function isSwedishUserMessage(message: string): boolean {
/clearingnummer/i,
/nummer är/i,
/tillgängligt/i,
/verifikation/i,
/importera|importen/i,
]
return swedishPatterns.some((p) => p.test(message))
}