OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-note commits / 3c69ffb

Fix TOC generation: add logging, remove silent error swallowing
regenerateToc() calls were wrapped in .catch(() => {}) which silently hid all errors. Now the function has its own try/catch with logging, and callers no longer suppress errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3c69ffb32613f5973ee53659666ac48ee4ecf125
by plankatron <fleeky@gmail.com> · 2026-03-19T02:15:05.000Z

Changed files (1) +32 -24

lib/note-manager.js +32 -24
……@@ -245,29 +245,37 @@ export class NoteManager {
245245 * Lists all notes (excluding README) alphabetically with slug links.
246246 */
247247 async regenerateToc (notebook) {
248 const meta = await this.getNotebook(notebook)
249 if (!meta || !meta.readmeId) return
248 try {
249 const meta = await this.getNotebook(notebook)
250 if (!meta || !meta.readmeId) return
250251
251 const readme = await this.getNote(notebook, meta.readmeId)
252 if (!readme) return
252 const readme = await this.getNote(notebook, meta.readmeId)
253 if (!readme) {
254 console.error(`[TOC] README note ${meta.readmeId} not found for ${notebook}`)
255 return
256 }
253257
254 const content = readme.content || ''
255 const startIdx = content.indexOf(TOC_START)
256 const endIdx = content.indexOf(TOC_END)
257 if (startIdx < 0 || endIdx < 0 || endIdx <= startIdx) return // Markers removed — no-op
258 const content = readme.content || ''
259 const startIdx = content.indexOf(TOC_START)
260 const endIdx = content.indexOf(TOC_END)
261 if (startIdx < 0 || endIdx < 0 || endIdx <= startIdx) return
258262
259 // Build TOC entries from all notes except README
260 const notes = await this.listNotes(notebook)
261 const entries = notes
262 .filter(n => n.id !== meta.readmeId)
263 .sort((a, b) => (a.title || '').localeCompare(b.title || ''))
264 .map(n => `- [${n.title || 'Untitled'}](${n.slug || n.id})`)
263 // Build TOC entries from all notes except README
264 const notes = await this.listNotes(notebook)
265 const nonReadme = notes.filter(n => n.id !== meta.readmeId)
266 const entries = nonReadme
267 .sort((a, b) => (a.title || '').localeCompare(b.title || ''))
268 .map(n => `- [${n.title || 'Untitled'}](${n.slug || n.id})`)
265269
266 const tocContent = entries.length > 0 ? '\n' + entries.join('\n') + '\n' : '\n'
267 const newContent = content.substring(0, startIdx + TOC_START.length) + tocContent + content.substring(endIdx)
270 const tocContent = entries.length > 0 ? '\n' + entries.join('\n') + '\n' : '\n'
271 const newContent = content.substring(0, startIdx + TOC_START.length) + tocContent + content.substring(endIdx)
268272
269 if (newContent !== content) {
270 await this.updateNote(notebook, meta.readmeId, { content: newContent })
273 if (newContent !== content) {
274 await this.updateNote(notebook, meta.readmeId, { content: newContent })
275 console.log(`[TOC] Updated ${notebook} README: ${entries.length} entries`)
276 }
277 } catch (err) {
278 console.error(`[TOC] Failed to regenerate for ${notebook}: ${err.message}`)
271279 }
272280 }
273281
……@@ -597,7 +605,7 @@ export class NoteManager {
597605 updatedAt: Date.now()
598606 }
599607 // Regenerate TOC in background
600 this.regenerateToc(notebook).catch(() => {})
608 this.regenerateToc(notebook)
601609 return result
602610 }
603611
……@@ -642,7 +650,7 @@ export class NoteManager {
642650 }
643651
644652 // Regenerate TOC in background
645 this.regenerateToc(notebook).catch(() => {})
653 this.regenerateToc(notebook)
646654
647655 return note // Return plaintext to caller
648656 }
……@@ -840,7 +848,7 @@ export class NoteManager {
840848 }
841849 const result = { ...note, id: note.noteId, content }
842850 // Regenerate TOC if title changed
843 if (titleChanged) this.regenerateToc(notebook).catch(() => {})
851 if (titleChanged) this.regenerateToc(notebook)
844852 return result
845853 }
846854
……@@ -875,7 +883,7 @@ export class NoteManager {
875883 }
876884
877885 // Regenerate TOC if title changed
878 if (titleChanged) this.regenerateToc(notebook).catch(() => {})
886 if (titleChanged) this.regenerateToc(notebook)
879887
880888 return note // Return plaintext
881889 }
……@@ -886,7 +894,7 @@ export class NoteManager {
886894 if (snb) {
887895 await snb.deleteNote(noteId, 'user')
888896 // Regenerate TOC in background
889 this.regenerateToc(notebook).catch(() => {})
897 this.regenerateToc(notebook)
890898 return { deleted: true, id: noteId }
891899 }
892900
……@@ -922,7 +930,7 @@ export class NoteManager {
922930
923931 // Regenerate TOC in background (only if we didn't just delete the README)
924932 if (!meta || meta.readmeId !== noteId) {
925 this.regenerateToc(notebook).catch(() => {})
933 this.regenerateToc(notebook)
926934 }
927935
928936 return { deleted: true, id: noteId }