RocketChat/Rocket.Chat · error · Error

error-operation-not-found

Error message

error-operation-not-found

What it means

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'.

Source

Thrown at apps/meteor/server/services/import/service.ts:158

			users.map((data) => ({
				_id: new ObjectId().toHexString(),
				data: {
					...data,
					roles: data.roles ? [...new Set([...data.roles, ...defaultRoles])] : defaultRoles,
				},
				dataType: 'user',
				_updatedAt: new Date(),
			})),
		);

		await Imports.increaseTotalCount(operation._id, 'users', users.length);
		await Imports.setOperationStatus(operation._id, 'importer_user_selection');
	}

	public async run(userId: string): Promise<void> {
		const operation = await Imports.findLastImport();
		if (!operation?.valid) {
			throw new Error('error-operation-not-found');
		}

		if (operation.status !== 'importer_user_selection') {
			throw new Error('error-invalid-operation-status');
		}

		const { importerKey } = operation;
		const importer = Importers.get(importerKey);
		if (!importer) {
			throw new Error('error-importer-not-defined');
		}

		// eslint-disable-next-line new-cap
		const instance = new importer.importer(importer, operation, {
			skipUserCallbacks: true,
			skipDefaultChannels: true,
			enableEmail2fa: settings.get<boolean>('Accounts_TwoFactorAuthentication_By_Email_Auto_Opt_In'),
			quickUserInsertion: true,

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Complete the upload/prepare phase so a valid operation exists before run()
  2. Re-check Imports.findLastImport()?.valid before starting the run
  3. Disable the start button/action until preparation reports success

Example fix

// before
await service.run(userId);

// after
const op = await Imports.findLastImport();
if (op?.valid && op.status === 'importer_user_selection') {
  await service.run(userId);
}
Defensive patterns

Strategy: validation

Validate before calling

const op = await Imports.findLastImport();
if (!op?.valid) {
  throw new Error('no valid import operation; complete the upload step first');
}
if (op.status !== 'importer_user_selection') {
  throw new Error(`operation not ready to run (status: ${op.status})`);
}
await service.run(userId);

Type guard

function isRunnableImport(op: IImport | undefined): op is IImport {
  return Boolean(op?.valid) && op.status === 'importer_user_selection';
}

Try / catch

try { await service.run(userId); } catch (e) { if (e.message === 'error-operation-not-found') { /* restart the prepare phase */ } }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/e3f669e0cbdd6de0. Report an issue: GitHub.