{"record":{"id":"539e5f4f917e5af7","repo":"tonhowtf/omniget","slug":"rename-failed","errorCode":null,"errorMessage":"rename failed","messagePattern":"rename failed","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/lib/study-notes/notebooks-store.svelte.ts","lineNumber":120,"sourceCode":"    color?: string | null;\n    iconLucide?: string | null;\n  }): Promise<number | null> {\n    try {\n      const r = await notesNotebooksCreate(args);\n      await this.refresh();\n      return r.notebook_id;\n    } catch (e) {\n      console.warn(\"create notebook failed\", e);\n      return null;\n    }\n  }\n\n  async rename(notebookId: number, newName: string) {\n    try {\n      await notesNotebooksRename({ notebookId, newName });\n      await this.refresh();\n    } catch (e) {\n      console.warn(\"rename failed\", e);\n    }\n  }\n\n  async close(notebookId: number) {\n    try {\n      await notesNotebooksClose(notebookId);\n      if (this.activeId === notebookId) {\n        await this.setActive(1);\n      }\n      await this.refresh();\n    } catch (e) {\n      console.warn(\"close failed\", e);\n    }\n  }\n\n  async reopen(notebookId: number) {\n    try {\n      await notesNotebooksReopen(notebookId);","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src/lib/study-notes/notebooks-store.svelte.ts#L102-L138","documentation":"notebooksStore.rename() persists a notebook rename via notesNotebooksRename (Tauri command 'study:notes:notebooks:rename') and then refresh(). If the command rejects, the catch logs 'rename failed' and the UI keeps the old name after refresh, with no error surfaced to the user.","triggerScenarios":"notesNotebooksRename({notebookId, newName}) rejects: notebookId does not exist, backend rejects the new name (empty/too long/duplicate), DB write failure, plugin/capability misconfiguration, or generic IPC failure.","commonSituations":"Renaming a notebook deleted in another window/session; empty name submitted; name exceeding backend length limit; DB locked; command renamed on backend so the bridge call 404s at invoke level.","solutions":["Read the logged rejection reason from notesNotebooksRename.","Validate newName (non-empty, length limit) client-side before calling rename().","Verify the notebook still exists (pageCountOf/list) before renaming.","Check the 'study:notes:notebooks:rename' command and capability registration.","Surface a user-visible toast on failure since refresh() will silently restore the old name."],"exampleFix":"// before\nasync rename(notebookId: number, newName: string) {\n  try {\n    await notesNotebooksRename({ notebookId, newName });\n    await this.refresh();\n  } catch (e) {\n    console.warn(\"rename failed\", e);\n  }\n}\n// after\nasync rename(notebookId: number, newName: string) {\n  const name = newName.trim();\n  if (!name) throw new Error(\"Notebook name cannot be empty\");\n  try {\n    await notesNotebooksRename({ notebookId, newName: name });\n    await this.refresh();\n  } catch (e) {\n    console.warn(\"rename failed\", e);\n    throw e; // let the UI show the failure\n  }\n}","handlingStrategy":"validation","validationCode":"function validateRename(id: number, newName: string): string | null {\n  const n = newName.trim();\n  if (!n) return 'Name cannot be empty';\n  if (n.length > 100) return 'Name too long';\n  if (!notebooksStore.list.some((nb) => nb.id === id)) return 'Notebook not found';\n  return null;\n}","typeGuard":"function notebookExistsIn(store: NotebooksStore, id: number): boolean {\n  return store.list.some((n) => n.id === id);\n}","tryCatchPattern":"try {\n  await notebooksStore.rename(id, newName.trim());\n} catch (e) {\n  console.warn('rename rejected:', e);\n  showToast('Rename failed — the notebook kept its previous name');\n  await notebooksStore.refresh();\n}","preventionTips":["Validate name non-empty and within backend length limits before calling","Check the notebook still exists (list) before renaming","After a failed rename, refresh so the UI shows the true (old) name","Surface failures to the user — the store only logs them","Keep the rename command name synchronized with the backend"],"tags":["svelte","tauri","ipc","validation","error-handling"],"backgroundTag":"api-request-failed","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}