siyuan-note/siyuan · warning

plugin stopped

Error message

plugin stopped: %w

What it means

addStorageWatch registers a path on the plugin's fsnotify watcher. Before doing so it checks p.context.Err(); if the plugin's context is already cancelled (plugin stopped/unloaded), it refuses with 'plugin stopped: <context error>'. This prevents watching files for a plugin that is no longer running.

Solutions

  1. Do not register storage watches after plugin unload; cancel pending async work on unload
  2. Check plugin lifecycle state before calling watch APIs
  3. Serialize shutdown so watches are removed before the context is cancelled
  4. In tests, create the watcher before cancelling the plugin context

Example fix

// before
plugin.addStorageWatch(path); // may run after unload

// after
if (!plugin.stopped) {
  plugin.addStorageWatch(path);
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (plugin.context?.signal?.aborted) {
  throw new Error("plugin stopped; cannot add storage watch");
}

Try / catch

try {
  plugin.addStorageWatch(path);
} catch (e) {
  if (String(e).startsWith("plugin stopped")) {
    return; // plugin already unloaded; skip registration
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling addStorageWatch (indirectly via storage watch APIs) after the plugin has been stopped or unloaded, or racing a stop with a watch registration. Also surfaced in tests that exercise lazy watcher creation after context cancellation.

Common situations: Async callbacks firing after plugin unload; storage watch requests queued while the plugin is being disabled; race between plugin shutdown and lazy watcher initialization.

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/5bf979dc55d68da5. Report an issue: GitHub.

Appendix: source

Thrown at kernel/plugin/plugin.go:776

			if !ok {
				return
			}
			logging.LogErrorf("[plugin:%s] storage watcher error: %s", p.Name, err)
		}
	}
}

// addStorageWatch adds a path to the fsnotify watcher to watch for storage file/directory changes.
func (p *KernelPlugin) addStorageWatch(path string) (err error) {
	if !isPluginFileWatchSupported() {
		return errPluginFileWatchUnsupported
	}

	p.watcherMu.Lock()
	defer p.watcherMu.Unlock()

	if contextErr := p.context.Err(); contextErr != nil {
		return fmt.Errorf("plugin stopped: %w", contextErr)
	}
	if p.watcher == nil {
		p.watcher, err = fsnotify.NewWatcher()
		if err != nil {
			return fmt.Errorf("initialize fsnotify watcher: %w", err)
		}
		p.watcherDone = make(chan struct{})
		go p.startStorageWatch(p.watcher, p.watcherDone)
	}

	err = p.watcher.Add(path)
	return
}

// removeStorageWatch removes a path from the fsnotify watcher to stop watching for storage file/directory changes.
func (p *KernelPlugin) removeStorageWatch(path string) (err error) {
	if !isPluginFileWatchSupported() {
		return errPluginFileWatchUnsupported

View on GitHub (pinned to 9f775e8a12)