laurent22/joplin · error

No such note

Error message

No such note: ${noteId}

What it means

checkCanChangeLockState throws this when the note entity passed to enableNoteLock/disableNoteLock is null, i.e. no note with the given noteId exists. The lock-state change cannot proceed on a nonexistent note.

Solutions

  1. Load the note first and confirm it is non-null before calling enableNoteLock/disableNoteLock.
  2. Refresh the note list and use a current note id.
  3. Wrap in try-catch to handle deleted notes gracefully.
  4. Avoid caching note ids across sessions or syncs.

Example fix

// before
await joplin.commands.execute('enableNoteLock', noteId);
// after
if (await Note.load(noteId)) await joplin.commands.execute('enableNoteLock', noteId);
Defensive patterns

Strategy: validation

Validate before calling

const note = await Note.load(noteId);
if (note) await joplin.commands.execute('enableNoteLock', noteId);

Type guard

const isNote = (n: unknown): n is NoteEntity => !!n && typeof (n as NoteEntity).id === 'string';

Try / catch

try { await enableNoteLock(noteId); } catch (e) { if (String(e.message).startsWith('No such note')) refreshNoteList(); else throw e; }

Prevention

When it happens

Trigger: Invoking the note lock enable/disable commands with a noteId that was deleted, mistyped, or never created, so `Note.load` returned null and a null note was forwarded.

Common situations: Plugins holding stale note IDs after a delete; race conditions where the note is deleted between listing and locking; user typos in a command palette invocation.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of laurent22/joplin@981a03c5c9 (2026-09-17). Data as JSON: /api/errors/66ec7ad1190c33e7. Report an issue: GitHub.

Appendix: source

Thrown at packages/lib/services/noteLock/setNoteLockState.ts:16

import { ModelType } from '../../BaseModel';
import BaseItem from '../../models/BaseItem';
import ItemChange from '../../models/ItemChange';
import Note from '../../models/Note';
import Setting from '../../models/Setting';
import { itemIsReadOnlySync, ItemSlice } from '../../models/utils/readOnly';
import { NoteEntity } from '../database/types';
import eventManager, { EventName } from '../../eventManager';
import isNoteLockEnabled from './isNoteLockEnabled';
import NoteLockSession from './NoteLockSession';

// The UI hides the enable/disable actions for these cases, but the commands can also be
// invoked directly (keyboard, plugins), so the transitions fail closed here too.
const checkCanChangeLockState = (note: NoteEntity, noteId: string) => {
	if (!isNoteLockEnabled()) throw new Error('Note lock is not enabled');
	if (!note) throw new Error(`No such note: ${noteId}`);
	if (note.deleted_time) throw new Error('Cannot change the note lock of a deleted note');
	if (note.is_conflict) throw new Error('Cannot change the note lock of a conflict note');
	if (itemIsReadOnlySync(ModelType.Note, ItemChange.SOURCE_UNSPECIFIED, note as ItemSlice, Setting.value('sync.userId'), BaseItem.syncShareCache)) throw new Error('Cannot change the note lock of a read-only note');
	if (!NoteLockSession.instance().isUnlocked()) throw new Error('Cannot change the note lock while the session is locked');
};

const validationFields = ['id', 'is_locked', 'deleted_time', 'is_conflict', 'share_id'];

// These only validate and emit: the note screen listens for the event and persists the
// change with a scheduled gated save.
export const enableNoteLock = async (noteId: string) => {
	const note = await Note.load(noteId, { fields: validationFields });
	checkCanChangeLockState(note, noteId);
	if (note.is_locked) throw new Error(`Note is already locked: ${noteId}`);
	eventManager.emit(EventName.NoteLockNoteStateChange, { noteId, isLocked: true });
};

export const disableNoteLock = async (noteId: string) => {

View on GitHub (pinned to 981a03c5c9)