RocketChat/Rocket.Chat · error · Error

The current import operation is already finished.

Error message

The current import operation is already finished.

What it means

Thrown by assertsValidStateForNewData when the last import operation is in a terminal state: 'done', 'error' or 'canceled'. Once an import finishes (successfully or not), the operation record is closed and cannot receive new data; a fresh operation must be started instead.

Source

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

		return {
			state,
			operation,
		};
	}

	private assertsValidStateForNewData(operation: IImport | undefined): asserts operation is IImport {
		if (!operation?.valid) {
			throw new Error('Import operation not initialized.');
		}
		const state = this.getStateOfOperation(operation);
		switch (state) {
			case 'loading':
			case 'importing':
				throw new Error('The current import operation can not receive new data.');
			case 'done':
			case 'error':
			case 'canceled':
				throw new Error('The current import operation is already finished.');
		}
	}

	public async addUsers(users: Omit<IImportUser, '_id' | 'services' | 'customFields'>[]): Promise<void> {
		if (!users.length) {
			return;
		}

		const operation = await Imports.findLastImport();

		this.assertsValidStateForNewData(operation);

		const defaultRoles = getNewUserRoles();
		const userRoles = new Set<string>(defaultRoles);
		for await (const user of users) {
			if (!user.emails?.some((value) => value) || !user.importIds?.some((value) => value)) {
				throw new Error('Users are missing required data.');
			}

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Start a new import operation rather than reusing the finished one
  2. Check operation.state before uploading and branch to the start flow when it is terminal
  3. Clear client-side references to the old operation after completion
Defensive patterns

Strategy: validation

Validate before calling

const op = await Imports.findLastImport();
if (['done', 'error', 'canceled'].includes(op?.status ?? '')) {
  throw new Error('operation finished; start a new import');
}

Type guard

function isTerminalImportState(state: string | undefined): boolean {
  return state === 'done' || state === 'error' || state === 'canceled';
}

Prevention

When it happens

Trigger: Calling addUsers(...) after run() completed with state 'done'; retrying an upload against an operation that ended in 'error'; adding data to an operation the user canceled.

Common situations: Retrying a failed import by re-uploading into the same operation instead of starting a new one; background jobs that keep feeding a completed migration; canceled imports leaving stale client state.

Related errors


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