simonlast / node-persist

Super-easy persistent data structures in Node.js
MIT License
719 stars 78 forks source link

(node:7636) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'ttl' of undefined #116

Closed Vanilagy closed 5 years ago

Vanilagy commented 5 years ago

[2019-01-02T13:45:59.111Z] (node:7636) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'ttl' of undefined at isExpired (C:...\node_modules\node-persist\src\local-storage.js:43:15) at Array.filter () at LocalStorage.keys (C:...\node_modules\node-persist\src\local-storage.js:111:16) at [2019-01-02T13:45:59.114Z] (node:7636) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) [2019-01-02T13:45:59.115Z] (node:7636) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I just got this error today. NO clue where it's coming from.

akhoury commented 5 years ago

which version are you using?

Vanilagy commented 5 years ago

I'm using node-persist@3.0.1

akhoury commented 5 years ago

looks like datum is undefined, which is weird, but I don't think I can debug this without looking at your directory, if it's not sensitive information, can you compress your directory and share it with me? privately if you prefer, to bentael@gmail.com

https://github.com/simonlast/node-persist/blob/ee0b08899524a9ed9b0dbe050c597b220a18d6e9/src/local-storage.js#L42

Vanilagy commented 5 years ago

Uh, I'm sorry, but it is quite sensitive information. Or rather, it's my school's information that they'd like to keep private. My fix was to just add "return datum && datum.ttl..." so it wouldn't throw. Regarding what caused this, I'm sorry but I couldn't find the reason. This bug just appeared to me suddenly one day.

Maybe it has to do with the file not loading correctly? My storage options are {forgiveParseErrors: true, ttl: false}.

akhoury commented 5 years ago

oh ok no problem, i pushed a possible fix, i think you might have another process/application accessing the same directory and leaving unparseable files in there, like Google Drive or something else, then when you forgiveParseErrors these datum resolved here is undefined

Anyways, pushed fix to 3.0.3 - but anyways, if you set forgiveParseErrors: false then rerun your app, you should be able to catch the culprit file.