RocketChat/Rocket.Chat · error · Error
Import operation not initialized.
Error message
Import operation not initialized.
What it means
Thrown by the import service's assertsValidStateForNewData when Imports.findLastImport() returns no operation or one with valid !== true — i.e. no import operation has been started (or the last one is invalid). All add* methods (addUsers, addChannels, addMessages, ...) run this assertion before accepting data, so data uploads before an import is opened are rejected.
Source
Thrown at apps/meteor/server/services/import/service.ts:98
const operation = await Imports.findLastImport();
if (!operation) {
return {
state: 'none',
};
}
const state = this.getStateOfOperation(operation);
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;
}
View on GitHub (pinned to b2c16d5842)
Solutions
- Start a valid import operation first (the importer's upload/start flow must create it)
- Re-run the upload step so Imports.findLastImport() returns a valid operation
- Check the last import record before pushing data
Example fix
// before
await service.addUsers(users);
// after
const op = await Imports.findLastImport();
if (!op?.valid) throw new Error('Start an import operation first');
await service.addUsers(users); Defensive patterns
Strategy: validation
Validate before calling
const op = await Imports.findLastImport();
if (!op?.valid) {
throw new Error('start an import operation before uploading data');
}
await service.addUsers(users); Type guard
function isValidImportOperation(op: IImport | undefined | null): op is IImport {
return Boolean(op && op.valid);
} Try / catch
try { await service.addUsers(users); } catch (e) { if (e.message === 'Import operation not initialized.') { /* run the upload/start flow, then retry once */ } } Prevention
- Always run the importer's start/upload step before pushing records
- Check the last operation's validity before every batch
When it happens
Trigger: Calling importService.addUsers(...) without a prior successful start/upload that created a valid IImport document; the last import record marked invalid by a failed upload; a fresh workspace where the Imports collection is empty.
Common situations: Importer flows that skip the file-upload/start step; restarts that lose in-memory assumptions while the database record was invalidated; concurrent import attempts where one cancels the operation record.
Related errors
- The current import operation can not receive new data.
- The current import operation is already finished.
- error-operation-not-found
- error-invalid-operation-status
- error-importer-not-defined
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/a314b60576839466.
Report an issue: GitHub.