{"record":{"id":"0419ef0a8b5fcab2","repo":"laurent22/joplin","slug":"no-item-with-id-itemid","errorCode":null,"errorMessage":"No item with ID ${itemId}","messagePattern":"No item with ID (.+?)","errorType":"http","errorClass":"Error","httpStatus":400,"severity":"warning","filePath":"packages/app-cli/app/app-gui.ts","lineNumber":712,"sourceCode":"\t\t\t\t\treturn url;\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\n\t\tthis.resourceServer_ = new ResourceServer();\n\t\tthis.resourceServer_.setLogger(this.app().logger());\n\t\tthis.resourceServer_.setLinkHandler(async (path, response) => {\n\t\t\tconst link = noteLinks[path];\n\n\t\t\tif (link.type === 'url') {\n\t\t\t\tresponse.writeHead(302, { Location: link.url });\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tif (link.type === 'item') {\n\t\t\t\tconst itemId = link.id;\n\t\t\t\tconst item = await BaseItem.loadItemById(itemId);\n\t\t\t\tif (!item) throw new Error(`No item with ID ${itemId}`); // Should be nearly impossible\n\n\t\t\t\tif (item.type_ === BaseModel.TYPE_RESOURCE) {\n\t\t\t\t\tif (item.mime) response.setHeader('Content-Type', item.mime);\n\t\t\t\t\tresponse.write(await Resource.content(item));\n\t\t\t\t} else if (item.type_ === BaseModel.TYPE_NOTE) {\n\t\t\t\t\tconst html = [\n\t\t\t\t\t\t`\n\t\t\t\t\t\t<!DOCTYPE html>\n\t\t\t\t\t\t<html class=\"client-nojs\" lang=\"en\" dir=\"ltr\">\n\t\t\t\t\t\t<head><meta charset=\"UTF-8\"/></head><body>\n\t\t\t\t\t`,\n\t\t\t\t\t];\n\t\t\t\t\thtml.push(`<pre>${htmlentities(item.title)}\\n\\n${htmlentities(item.body)}</pre>`);\n\t\t\t\t\thtml.push('</body></html>');\n\t\t\t\t\tresponse.write(html.join(''));\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(`Unsupported item type: ${item.type_}`);\n\t\t\t\t}","sourceCodeStart":694,"sourceCodeEnd":730,"githubUrl":"https://github.com/laurent22/joplin/blob/2654b33620775080d1d59c552259d41e33dad3d2/packages/app-cli/app/app-gui.ts#L694-L730","documentation":"Inside the resource-server link handler, an internal link of type 'item' is resolved by loading the referenced item from the database via BaseItem.loadItemById(itemId). loadItemById iterates the sync item classes and returns null if no class has a row with that id. If the result is null the handler throws 'No item with ID'. The source comment marks this 'Should be nearly impossible', and the throw is caught by ResourceServer and turned into a 400 response.","triggerScenarios":"A note contains an internal link (joplin:///:/itemId) whose target has been deleted; the link id is truncated or corrupted; the referenced item has not yet been synced to this device so it is absent from the local database.","commonSituations":"Opening a note on a freshly synced device where linked items have not downloaded yet; dangling links left after deleting a linked note/resource; manual or partial database edits that orphan an id.","solutions":["Trigger a sync so the referenced item is downloaded into the local database.","Remove or repair the dangling internal link in the note markdown.","Handle the null result gracefully by writing a 'resource not found' message to the response and returning true, instead of throwing."],"exampleFix":"// before\n//   const item = await BaseItem.loadItemById(itemId);\n//   if (!item) throw new Error(`No item with ID ${itemId}`);\n// after\n//   const item = await BaseItem.loadItemById(itemId);\n//   if (!item) {\n//     response.statusCode = 404;\n//     response.write(`Item not found: ${itemId}`);\n//     return true;\n//   }","handlingStrategy":"validation","validationCode":"const item = await BaseItem.loadItemById(itemId);\nif (!item) {\n  response.statusCode = 404;\n  response.write(`Item not found: ${itemId}`);\n  return true;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat loadItemById results as nullable and write a user-facing message instead of throwing inside the HTTP handler.","Sync before opening notes whose links may reference items not yet on this device.","Periodically prune or flag dangling internal links in notes."],"tags":["resource-server","note-link","database","sync","e2ee"],"backgroundTag":null,"analyzedSha":"2654b33620775080d1d59c552259d41e33dad3d2","analyzedAt":"2026-08-12T14:26:46.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}