zadam / trilium

Build your personal knowledge base with Trilium Notes
GNU Affero General Public License v3.0
27.2k stars 1.9k forks source link

(Bug report) Cannot read properties of undefined (reading 'normalize') #3469

Closed agentydragon closed 1 year ago

agentydragon commented 1 year ago

Trilium Version

0.57.5

What operating system are you using?

Ubuntu

What is your setup?

Local + server sync

Operating System Version

Pop!_OS 22.04 LTS

Description

happens to me on some autocomplete queries, see screenshot below. not sure how this happened, perhaps some note in db in a weird state?

persists after both "check database integrity" and "find and fix consistency issues".

db version is 197, sync version 26

image

Error logs

...
02:02:00.138 Slow query took 3810ms: PRAGMA integrity_check
02:02:00.139 Integrity check result: [{"integrity_check":"ok"}]
02:02:00.139 Slow 200 GET /api/database/check-integrity with 38 bytes took 3812ms
02:02:05.425 ERROR: get /api/autocomplete threw exception: TypeError: Cannot read properties of undefined (reading 'normalize')
    at removeDiacritic (/usr/lib/trilium/resources/app.asar/src/services/utils.js:294:16)
    at Object.normalize (/usr/lib/trilium/resources/app.asar/src/services/utils.js:298:12)
    at NoteFlatTextExp.execute (/usr/lib/trilium/resources/app.asar/src/services/search/expressions/note_flat_text.js:93:31)
    at AndExp.execute (/usr/lib/trilium/resources/app.asar/src/services/search/expressions/and.js:26:42)
    at findResultsWithExpression (/usr/lib/trilium/resources/app.asar/src/services/search/services/search.js:151:32)
    at findResultsWithQuery (/usr/lib/trilium/resources/app.asar/src/services/search/services/search.js:247:12)
    at Object.searchNotesForAutocomplete (/usr/lib/trilium/resources/app.asar/src/services/search/services/search.js:268:30)
    at getAutocomplete (/usr/lib/trilium/resources/app.asar/src/routes/api/autocomplete.js:22:33)
    at Function.cb (/usr/lib/trilium/resources/app.asar/src/routes/routes.js:159:34)
    at Function.sqliteTransaction (/usr/lib/trilium/resources/app.asar/node_modules/better-sqlite3/lib/methods/transaction.js:65:24)
02:02:05.445 JS Error: Error when calling GET /api/autocomplete?query=e&activeNoteId=jlRBrkh3OZbj: 500 - Cannot read properties of undefined (reading 'normalize')
Stack: Error
    at Object.C [as logError] (http://127.0.0.1:37840/assets/v0.57.5/app-dist/desktop.js:2:96330)
    at Object.throwError (http://127.0.0.1:37840/assets/v0.57.5/app-dist/desktop.js:2:81380)
    at c (http://127.0.0.1:37840/assets/v0.57.5/app-dist/desktop.js:2:78040)
    at async EventEmitter.<anonymous> (http://127.0.0.1:37840/assets/v0.57.5/app-dist/desktop.js:2:78892)
02:02:06.495 Slow 200 GET /api/autocomplete?query=&activeNoteId=jlRBrkh3OZbj with 66598 bytes took 13ms
02:02:06.797 200 PUT /api/notes/jlRBrkh3OZbj/attribute with 2 bytes took 1ms
02:02:09.713 304 GET /api/clipper/handshake with 45 bytes took 2ms
02:02:10.044 200 GET /api/options with 6818 bytes took 0ms
02:02:10.045 Keyboard action showNoteInfo found in database, but not in action definition.
...
zadam commented 1 year ago

Hi, thanks for reporting.

I don't think it's caused by wrong data in the database - this happens because of attribute's name being null/undefined, but the DB has NOT NULL constraint on that column. So it's rather some kind of ephemeral state error in the application, but from looking at the code I did not find where it could originate from (it could come also from user scripts).

I've made the code more robust to not fail on this.

agentydragon commented 1 year ago

huh, that's weird. i wonder how did it get into my database. i do have a bunch of user scripts, but they all use the trilium script api and/or etapi, so i'd still expect the db-level integrity checks to apply and prevent it. oh well, thanks for looking into it!

zadam commented 1 year ago

i wonder how did it get into my database

I don't think it did. It errors out on the in-memory object. I suspect that the null/undefined sneaked into the in-memory object, but not into the database (because of the DB constraint).