diff --git a/server/commands/documentImporter.ts b/server/commands/documentImporter.ts index 2d9f9ac2a..f014280be 100644 --- a/server/commands/documentImporter.ts +++ b/server/commands/documentImporter.ts @@ -77,6 +77,13 @@ async function documentImporter({ transaction ); + // Sanity check – text cannot possibly be longer than state so if it is, we can short-circuit here + if (text.length > DocumentValidation.maxStateLength) { + throw InvalidRequestError( + `The document "${title}" is too large to import, please reduce the length and try again` + ); + } + // It's better to truncate particularly long titles than fail the import title = truncate(title, { length: DocumentValidation.maxTitleLength });