{"record":{"id":"e3f669e0cbdd6de0","repo":"RocketChat/Rocket.Chat","slug":"error-operation-not-found-e3f669","errorCode":null,"errorMessage":"error-operation-not-found","messagePattern":"error-operation-not-found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/services/import/service.ts","lineNumber":158,"sourceCode":"\t\t\tusers.map((data) => ({\n\t\t\t\t_id: new ObjectId().toHexString(),\n\t\t\t\tdata: {\n\t\t\t\t\t...data,\n\t\t\t\t\troles: data.roles ? [...new Set([...data.roles, ...defaultRoles])] : defaultRoles,\n\t\t\t\t},\n\t\t\t\tdataType: 'user',\n\t\t\t\t_updatedAt: new Date(),\n\t\t\t})),\n\t\t);\n\n\t\tawait Imports.increaseTotalCount(operation._id, 'users', users.length);\n\t\tawait Imports.setOperationStatus(operation._id, 'importer_user_selection');\n\t}\n\n\tpublic async run(userId: string): Promise<void> {\n\t\tconst operation = await Imports.findLastImport();\n\t\tif (!operation?.valid) {\n\t\t\tthrow new Error('error-operation-not-found');\n\t\t}\n\n\t\tif (operation.status !== 'importer_user_selection') {\n\t\t\tthrow new Error('error-invalid-operation-status');\n\t\t}\n\n\t\tconst { importerKey } = operation;\n\t\tconst importer = Importers.get(importerKey);\n\t\tif (!importer) {\n\t\t\tthrow new Error('error-importer-not-defined');\n\t\t}\n\n\t\t// eslint-disable-next-line new-cap\n\t\tconst instance = new importer.importer(importer, operation, {\n\t\t\tskipUserCallbacks: true,\n\t\t\tskipDefaultChannels: true,\n\t\t\tenableEmail2fa: settings.get<boolean>('Accounts_TwoFactorAuthentication_By_Email_Auto_Opt_In'),\n\t\t\tquickUserInsertion: true,","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/services/import/service.ts#L140-L176","documentation":"Thrown by the import service's run() when Imports.findLastImport() returns no operation or one with valid !== true. run() executes the prepared import; calling it before an upload/start created a valid operation, or after the record was invalidated, fails fast with the machine-readable code 'error-operation-not-found'.","triggerScenarios":"Calling service.run(userId) on a workspace with no import history; run() invoked after a canceled/invalidated operation cleared validity; race where run() is triggered before the upload transaction commits the operation.","commonSituations":"Import UIs that allow 'Start import' before file processing finishes; API-driven imports that skip the preparation step; retries after a failed import invalidated the record.","solutions":["Complete the upload/prepare phase so a valid operation exists before run()","Re-check Imports.findLastImport()?.valid before starting the run","Disable the start button/action until preparation reports success"],"exampleFix":"// before\nawait service.run(userId);\n\n// after\nconst op = await Imports.findLastImport();\nif (op?.valid && op.status === 'importer_user_selection') {\n  await service.run(userId);\n}","handlingStrategy":"validation","validationCode":"const op = await Imports.findLastImport();\nif (!op?.valid) {\n  throw new Error('no valid import operation; complete the upload step first');\n}\nif (op.status !== 'importer_user_selection') {\n  throw new Error(`operation not ready to run (status: ${op.status})`);\n}\nawait service.run(userId);","typeGuard":"function isRunnableImport(op: IImport | undefined): op is IImport {\n  return Boolean(op?.valid) && op.status === 'importer_user_selection';\n}","tryCatchPattern":"try { await service.run(userId); } catch (e) { if (e.message === 'error-operation-not-found') { /* restart the prepare phase */ } }","preventionTips":["Enable the start action only after preparation completes","Re-check operation validity and status immediately before run()"],"tags":["import","state-machine","lifecycle","rocket-chat"],"backgroundTag":"invalid-operation-state","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}