farux / obsidian-auto-note-mover

This is a plugin for Obsidian (https://obsidian.md).
MIT License
290 stars 22 forks source link

Auto note mover seems to conflict with the Readwise Official plugin #50

Open FeralFlora opened 1 year ago

FeralFlora commented 1 year ago

The Readwise Official plugin stopped working and I was getting multiple errors in the console. One of the mentioned both Auto Note Mover and Readwise Official:

app.js:1 Uncaught TypeError: Cannot read properties of null (reading 'frontmatter')
    at isFmDisable (plugin:auto-note-mover:1806:68)
    at fileCheck (plugin:auto-note-mover:2079:13)
    at eval (plugin:auto-note-mover:2125:66)
    at e.tryTrigger (app.js:1:1064472)
    at e.trigger (app.js:1:1064405)
    at t.trigger (app.js:1:1132563)
    at t.onChange (app.js:1:1122926)
    at e.trigger (app.js:1:1112321)
    at e.<anonymous> (app.js:1:1110393)
    at app.js:1:235836
isFmDisable @   plugin:auto-note-mover:1806
fileCheck   @   plugin:auto-note-mover:2079
eval    @   plugin:auto-note-mover:2125
e.tryTrigger    @   app.js:1
e.trigger   @   app.js:1
t.trigger   @   app.js:1
t.onChange  @   app.js:1
e.trigger   @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
v   @   app.js:1
e.reconcileFileCreation @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
a   @   app.js:1
setTimeout (async)      
e.tryTrigger    @   app.js:1
e.trigger   @   app.js:1
t.trigger   @   app.js:1
t.onChange  @   app.js:1
e.trigger   @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
v   @   app.js:1
e.reconcileFileCreation @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
a   @   app.js:1
Promise.then (async)        
l   @   app.js:1
(anonymous) @   app.js:1
v   @   app.js:1
e.reconcileFileInternal @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
a   @   app.js:1
Promise.then (async)        
l   @   app.js:1
a   @   app.js:1
Promise.then (async)        
l   @   app.js:1
(anonymous) @   app.js:1
v   @   app.js:1
e.reconcileFile @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
v   @   app.js:1
e.reconcileInternalFile @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
(anonymous) @   app.js:1
a   @   app.js:1
Promise.then (async)        
l   @   app.js:1
a   @   app.js:1
Promise.then (async)        
l   @   app.js:1
(anonymous) @   app.js:1
v   @   app.js:1
(anonymous) @   app.js:1
n   @   app.js:1
Promise.then (async)        
e.queue @   app.js:1
e.write @   app.js:1
eval    @   plugin:readwise-official:8023
fulfilled   @   plugin:readwise-official:28
Promise.then (async)        
step    @   plugin:readwise-official:30
fulfilled   @   plugin:readwise-official:28
Promise.then (async)        
step    @   plugin:readwise-official:30
fulfilled   @   plugin:readwise-official:28
Promise.then (async)        
step    @   plugin:readwise-official:30
fulfilled   @   plugin:readwise-official:28
Promise.then (async)        
step    @   plugin:readwise-official:30
fulfilled   @   plugin:readwise-official:28
Promise.then (async)        
step    @   plugin:readwise-official:30
fulfilled   @   plugin:readwise-official:28
Promise.then (async)        
step    @   plugin:readwise-official:30
fulfilled   @   plugin:readwise-official:28
Promise.then (async)        
step    @   plugin:readwise-official:30
fulfilled   @   plugin:readwise-official:28
Promise.then (async)        
step    @   plugin:readwise-official:30
fulfilled   @   plugin:readwise-official:28
Promise.then (async)        
step    @   plugin:readwise-official:30
fulfilled   @   plugin:readwise-official:28
Promise.then (async)        
step    @   plugin:readwise-official:30
fulfilled   @   plugin:readwise-official:28

Because of this, I tried disabling Auto Note Mover, and now Readwise Official suddenly works again.

This error points to line 1806 in Auto Note Mover. The function on that line is:

var isFmDisable = (fileCache) => {
  const fm = (0, import_obsidian4.parseFrontMatterEntry)(fileCache.frontmatter, "AutoNoteMover");
  if (fm === "disable") {
    return true;
  } else {
    return false;
  }
};

Line 1802 in Readwise official is also mentioned, and that spans this snippet:

// Write the zlib header
        if (status == INIT_STATE) {
            header = (Z_DEFLATED$1 + ((w_bits - 8) << 4)) << 8;
            level_flags = ((level - 1) & 0xff) >> 1;

            if (level_flags > 3)
                level_flags = 3;
            header |= (level_flags << 6);
            if (strstart !== 0)
                header |= PRESET_DICT$1;
            header += 31 - (header % 31);

            status = BUSY_STATE;
            putShortMSB(header);
        }
jaewonE commented 3 months ago

I faced the same issue. After analyzing the code, I found that there were instances where fileCache was empty ({}), which led to the 'Cannot read properties of null' error. The root cause of this error was the absence of a valid fileCache. To resolve this, you need to ensure that fileCache exists.

In the file .obsidian/plugins/auto-nove-mover/main.js at line 2078,

below the line:

const fileCache = this.app.metadataCache.getFileCache(file);

add the following code:

if (!fileCache || Object.keys(fileCache).length === 0) {
    return;
}

This will check if the fileCache object is empty and resolve the issue.