{"record":{"id":"062c978805bd7c45","repo":"RocketChat/Rocket.Chat","slug":"error-import-operation-invalid","errorCode":"error-import-operation-invalid","errorMessage":"Invalid Import Operation","messagePattern":"Invalid Import Operation","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/import/getImportFileData.ts","lineNumber":43,"sourceCode":"\t\tthrow new Meteor.Error('error-importer-not-defined', `The importer (${importerKey}) has no import class defined.`, 'getImportFileData');\n\t}\n\n\tconst instance = new importer.importer(importer, operation); // eslint-disable-line new-cap\n\n\tconst waitingSteps: IImportProgress['step'][] = [\n\t\tProgressStep.DOWNLOADING_FILE,\n\t\tProgressStep.PREPARING_CHANNELS,\n\t\tProgressStep.PREPARING_MESSAGES,\n\t\tProgressStep.PREPARING_USERS,\n\t\tProgressStep.PREPARING_CONTACTS,\n\t\tProgressStep.PREPARING_STARTED,\n\t];\n\n\tif (waitingSteps.indexOf(instance.progress.step) >= 0) {\n\t\tif (instance.importRecord?.valid) {\n\t\t\treturn { waiting: true };\n\t\t}\n\t\tthrow new Meteor.Error('error-import-operation-invalid', 'Invalid Import Operation', 'getImportFileData');\n\t}\n\n\tconst readySteps: IImportProgress['step'][] = [\n\t\tProgressStep.USER_SELECTION,\n\t\tProgressStep.DONE,\n\t\tProgressStep.CANCELLED,\n\t\tProgressStep.ERROR,\n\t];\n\n\tif (readySteps.indexOf(instance.progress.step) >= 0) {\n\t\treturn instance.buildSelection();\n\t}\n\n\tconst fileName = instance.importRecord.file;\n\tif (fileName) {\n\t\tconst fullFilePath = fs.existsSync(fileName) ? fileName : path.join(RocketChatImportFileInstance.absolutePath, fileName);\n\t\tawait instance.prepareUsingLocalFile(fullFilePath);\n\t}","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/import/getImportFileData.ts#L25-L61","documentation":"Thrown by getImportFileData when the latest import operation is in one of the 'waiting' steps (DOWNLOADING_FILE, PREPARING_CHANNELS, PREPARING_MESSAGES, PREPARING_USERS, PREPARING_CONTACTS, PREPARING_STARTED) but its `importRecord.valid` flag is falsy. The method would normally return `{ waiting: true }` during preparation; an invalid record means preparation cannot be trusted to finish, so the operation is rejected as invalid.","triggerScenarios":"Polling `Meteor.call('getImportFileData')` while an import is mid-preparation whose upload record was marked invalid — e.g. the uploaded file failed validation, the server restarted during preparation, or the operation was interrupted between startFileUpload and the prep steps completing.","commonSituations":"Server crash/restart in the middle of preparing a large Slack or CSV import; uploading a truncated/corrupted export file that fails import-record validation; retrying an old import whose file entry in RocketChatImportFileInstance no longer validates.","solutions":["Call `Meteor.call('getImportProgress')` first to see the actual step and whether the operation is stuck","If the record is invalid, restart the flow: re-upload the file with `uploadImportFile` (this creates a new operation) instead of continuing to poll","Verify the source export file is complete and uncorrupted (re-download the Slack export, regenerate the CSV) before uploading","Avoid polling getImportFileData after a mid-preparation server restart; start a new import instead"],"exampleFix":"// before\nMeteor.call('getImportFileData', (err, data) => { /* error-import-operation-invalid while prep 'in progress' */ });\n\n// after — check progress, and when invalid restart the import cleanly\nMeteor.call('getImportProgress', (e, progress) => {\n  if (progress.step === 'preparing_users' && !progress.valid) {\n    Meteor.call('uploadImportFile', binaryContent, 'application/zip', 'export.zip', 'slack');\n  }\n});","handlingStrategy":"try-catch","validationCode":"// Poll progress first; only fetch file data when the operation looks healthy\nMeteor.call('getImportProgress', (e, p) => {\n  const WAITING = ['downloading_file', 'preparing_channels', 'preparing_messages', 'preparing_users', 'preparing_contacts', 'preparing_started'];\n  if (!WAITING.includes(p.step)) Meteor.call('getImportFileData', cb);\n});","typeGuard":null,"tryCatchPattern":"try {\n  const result = await meteorCall('getImportFileData');\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'error-import-operation-invalid') {\n    // record invalid: restart the flow with a fresh uploadImportFile\n  }\n}","preventionTips":["Stop polling getImportFileData after a server restart during preparation","Validate export archives (size/checksum) before upload so importRecord.valid stays true","Treat { waiting: true } as the only healthy mid-preparation response; anything else means restart"],"tags":["rocket-chat","import","invalid-state","meteor-methods"],"backgroundTag":"invalid-operation-state","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}