siyuan-note/siyuan · info

Conf.Language(331)

Error message

Conf.Language(331)

What it means

CancelObsidianVaultTask returns this error when the task exists but its State is not cancellable (e.g. already running past a checkpoint, completed, failed, or cancelled). The task snapshot is still returned so the caller can inspect the current state. i18n string 331 is "The Obsidian Vault import task can no longer be cancelled".

Solutions

  1. Check the returned task snapshot's State before attempting cancellation; skip if terminal
  2. Disable the cancel UI action once the task reports a non-cancellable state
  3. Retry cancellation immediately after starting the task only if you truly need a pre-emptive cancel, otherwise avoid the race

Example fix

// before
await cancelObsidianImport(taskID); // errors if already done
// after
const { data: task } = await getObsidianTask(taskID);
if (CANCELLABLE_STATES.includes(task.state)) {
  await cancelObsidianImport(taskID);
}
Defensive patterns

Strategy: type-guard

Validate before calling

const CANCELLABLE = ['analyzing', 'importing'];
if (!CANCELLABLE.includes(task.state)) return snapshotOnly(task);

Type guard

function isCancellable(t) { return t && typeof t.state === 'string' && ['analyzing','importing'].includes(t.state); }

Try / catch

try { await cancelObsidianImport(taskID); } catch (e) { const snap = extractTaskSnapshot(e); if (snap) updateUiState(snap.state); }

Prevention

When it happens

Trigger: Calling cancel on a task whose isObsidianCancellableState(task.State) is false — typically a task that already reached ObsidianTaskStateCancelled/Completed/Failed, or one in a terminal phase of import.

Common situations: Double-clicking a cancel button; racing another client that already cancelled; cancelling after the import finished successfully.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/773afa2d70305ac4. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/import_obsidian.go:295

	defer obsidianTasksMu.Unlock()
	task := obsidianTasks[taskID]
	if task == nil {
		return nil, errors.New(Conf.Language(330))
	}
	return snapshotObsidianTask(task), nil
}

func CancelObsidianVaultTask(taskID string) (*ObsidianVaultTask, error) {
	obsidianTasksMu.Lock()
	task := obsidianTasks[taskID]
	if task == nil {
		obsidianTasksMu.Unlock()
		return nil, errors.New(Conf.Language(330))
	}
	if !isObsidianCancellableState(task.State) {
		ret := snapshotObsidianTask(task)
		obsidianTasksMu.Unlock()
		return ret, errors.New(Conf.Language(331))
	}
	if task.Cancel != nil {
		task.Cancel()
	}
	finishObsidianTaskLocked(task, ObsidianTaskStateCancelled, "Import cancelled", "")
	ret := snapshotObsidianTask(task)
	obsidianTasksMu.Unlock()
	removeObsidianTemp(taskID)
	return ret, nil
}

func StartObsidianVaultImport(taskID, notebookName string) (*ObsidianVaultTask, error) {
	obsidianTasksMu.Lock()
	task := obsidianTasks[taskID]
	if task == nil || task.State != ObsidianTaskStateReady || task.Context == nil {
		obsidianTasksMu.Unlock()
		return nil, errors.New(Conf.Language(332))
	}

View on GitHub (pinned to 9f775e8a12)