retorquere / zotero-file-hierarchy

https://goo.gl/forms/dFD27RHUuArq6UEK2
81 stars 13 forks source link

Hierarchy with more than two levels not working #6

Closed RobinAlili closed 2 years ago

RobinAlili commented 3 years ago

First, many thanks for this excellent js! It seems that I've encountered one problem though:

If I export My Library. I'll get Folder A alright, but there are no Folder B, C and D. The files in B, C and D do exist, but in Folder A.

If I export Folder A. I'll get Folder A and B alright, but there are no Folder C and D. The files in C and D do exist, but in Folder A.

If I export Folder B. I'll get Folder B and C alright, but there are no Folder D. The files in D do exist, but in Folder B.

It seem that this js only works with hierarchy no more than two levels. Can you reproduce this or it's just me who might have somehow set it wrong? Thanks!

crliu95 commented 2 years ago

I have encoutered the same problem.

Besides, the files would be placed in the root folder if they are stored in more than one (sub-)collections. And folders do not exist for the (sub-)collections where all items are also stored in other (sub-)collections at the same time.

retorquere commented 2 years ago

@RobinAlili sorry I missed this issue. @crliu95 can you close down zotero (cmd-Q if you're on a mac) and get me a copy of your zotero.sqlite database?

edit: @crliu95 and can you give me a few specific names/folders that you expected to see/expected not to see?

crliu95 commented 2 years ago

@retorquere thanks for your instant reply! I was trying to created a minimum sample to replicate the bug that I mentioned above. And I just found that the folder was missing not for items in it being shared, but exactly due to the depth problem:

Folders would not be properly created for subcollections that are two-level deeper than the collection we want to export. But the items in these deep subcollections are successfully exported and located in the root folder.

So that's the only problem now.

retorquere commented 2 years ago

Can I still have a copy of your DB? I'd like to be sure we're looking at the same situation.

crliu95 commented 2 years ago

Of course and here it is the Dropbox shared link. And you can see the "0TestCollection" collection, which was the minimum sample that I created just now.

retorquere commented 2 years ago

Try the new version I just checked in.

crliu95 commented 2 years ago

Thanks for the quick fix. But there seems more bugs with the new version:

  1. No error messages show up but I do not see any files exported in the folder but an empty txt file, even if the check box "export files" is ticked. (encountered when trying to export the flat "0Reading" collection, which has no subcollections in it)

  2. An error message shows up when I try to export a collections with subcollections (even with just one-level depth).

here is part of the debug log:

`(3)(+0000003): Translate: Beginning translation with File Hierarchy

(3)(+0000001): Translate: collections: {"A7PTIPMI":"SubSubTestColl","QSA5DFGI":"SubTestColl"}

(5)(+0000010): Translate: Running handler 0 for itemDone

(1)(+0000002): NS_ERROR_FILE_UNRECOGNIZED_PATH Exception: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.append] _attachmentToArray/attachmentArray.saveFile@chrome://zotero/content/xpcom/translation/translate_item.js:1131:52 save@chrome://zotero/content/xpcom/translation/translate_firefox.js line 425 > eval:68:17 doExport@chrome://zotero/content/xpcom/translation/translate_firefox.js line 425 > eval:80:9 rest@chrome://zotero/content/xpcom/translation/translate.js:1356:28 Zotero.Translate.Base.prototype._translateTranslatorLoaded</<@chrome://zotero/content/xpcom/translation/translate.js:1346:37

(2)(+0000000): Translate: Translation using File Hierarchy failed: [Exception... "Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.append]" nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)" location: "JS frame :: chrome://zotero/content/xpcom/translation/translate_item.js :: _attachmentToArray/attachmentArray.saveFile :: line 1131" data: no] _attachmentToArray/attachmentArray.saveFile@chrome://zotero/content/xpcom/translation/translate_item.js:1131:52 save@chrome://zotero/content/xpcom/translation/translate_firefox.js line 425 > eval:68:17 doExport@chrome://zotero/content/xpcom/translation/translate_firefox.js line 425 > eval:80:9 rest@chrome://zotero/content/xpcom/translation/translate.js:1356:28 Zotero.Translate.Base.prototype._translateTranslatorLoaded</<@chrome://zotero/content/xpcom/translation/translate.js:1346:37 tryCatcher@resource://zotero/loader.jsm -> resource://zotero/bluebird/util.js:16:16 module.exports/Promise.prototype._settlePromiseFromHandler@resource://zotero/loader.jsm -> resource://zotero/bluebird/promise.js:547:13 module.exports/Promise.prototype._settlePromise@resource://zotero/loader.jsm -> resource://zotero/bluebird/promise.js:604:13 module.exports/Promise.prototype._settlePromise0@resource://zotero/loader.jsm -> resource://zotero/bluebird/promise.js:649:5 module.exports/Promise.prototype._settlePromises@resource://zotero/loader.jsm -> resource://zotero/bluebird/promise.js:729:13 _drainQueueStep@resource://zotero/loader.jsm -> resource://zotero/bluebird/async.js:93:9 _drainQueue@resource://zotero/loader.jsm -> resource://zotero/bluebird/async.js:86:9 Async.prototype._drainQueues@resource://zotero/loader.jsm -> resource://zotero/bluebird/async.js:102:5 Async/this.drainQueues@resource://zotero/loader.jsm -> resource://zotero/bluebird/async.js:15:9 url => C:\Users\Chenran\Downloads\0TestColl downloadAssociatedFiles => true

(5)(+0000000): Translate: Running handler 0 for error

(5)(+0000001): Translate: Running handler 0 for done

(3)(+0000000): Running unlock callbacks

(3)(+0000000): Alert: An error occurred while trying to export the selected file.`

retorquere commented 2 years ago

Since we're now looking at the same database, you can make this more precise; what we're you exporting, precisely, for the second case?

crliu95 commented 2 years ago

No problem.

  1. For the first case, I just tried to export the "0Reading" collection.
  2. For the second case, you can creat a subcollection under "0Reading", and move one item (e.g., Minetti et al. 2019) from the parent collection into it. After doing so, try to export the "0Reading" collection again.
retorquere commented 2 years ago

New version is up.

crliu95 commented 2 years ago

Thanks! And after a quick test, I think the first case is perfectly fixed. But the second case still exists, this time with part of files exported in the folder. The debug log is (where "Test" is the name of subcollection created under "0Reading") :

(3)(+0000001): Getting contents of C:\Users\Chenran\Zotero\translators\File Hierarchy.js

(4)(+0000006): Translate: Parsing code for File Hierarchy (86ffd88b-6f4e-4bec-a5be-839c1034beb2, 2021-12-30 09:46:53)

(3)(+0000003): Translate: Beginning translation with File Hierarchy

(3)(+0000000): Translate: collections: {"VB4HPZAC":"Test"}

(5)(+0000004): Translate: Running handler 0 for itemDone

(5)(+0000006): Translate: Running handler 0 for itemDone

(5)(+0000004): Translate: Running handler 0 for itemDone

(5)(+0000005): Translate: Running handler 0 for itemDone

(5)(+0000004): Translate: Running handler 0 for itemDone

(5)(+0000004): Translate: Running handler 0 for itemDone

(1)(+0000001): NS_ERROR_FILE_UNRECOGNIZED_PATH Exception: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.append] _attachmentToArray/attachmentArray.saveFile@chrome://zotero/content/xpcom/translation/translate_item.js:1131:52 save@chrome://zotero/content/xpcom/translation/translate_firefox.js line 425 > eval:70:17 doExport@chrome://zotero/content/xpcom/translation/translate_firefox.js line 425 > eval:82:9 rest@chrome://zotero/content/xpcom/translation/translate.js:1356:28 Zotero.Translate.Base.prototype._translateTranslatorLoaded</<@chrome://zotero/content/xpcom/translation/translate.js:1346:37

(2)(+0000000): Translate: Translation using File Hierarchy failed: [Exception... "Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.append]" nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)" location: "JS frame :: chrome://zotero/content/xpcom/translation/translate_item.js :: _attachmentToArray/attachmentArray.saveFile :: line 1131" data: no] _attachmentToArray/attachmentArray.saveFile@chrome://zotero/content/xpcom/translation/translate_item.js:1131:52 save@chrome://zotero/content/xpcom/translation/translate_firefox.js line 425 > eval:70:17 doExport@chrome://zotero/content/xpcom/translation/translate_firefox.js line 425 > eval:82:9 rest@chrome://zotero/content/xpcom/translation/translate.js:1356:28 Zotero.Translate.Base.prototype._translateTranslatorLoaded</<@chrome://zotero/content/xpcom/translation/translate.js:1346:37 tryCatcher@resource://zotero/loader.jsm -> resource://zotero/bluebird/util.js:16:16 module.exports/Promise.prototype._settlePromiseFromHandler@resource://zotero/loader.jsm -> resource://zotero/bluebird/promise.js:547:13 module.exports/Promise.prototype._settlePromise@resource://zotero/loader.jsm -> resource://zotero/bluebird/promise.js:604:13 module.exports/Promise.prototype._settlePromise0@resource://zotero/loader.jsm -> resource://zotero/bluebird/promise.js:649:5 module.exports/Promise.prototype._settlePromises@resource://zotero/loader.jsm -> resource://zotero/bluebird/promise.js:729:13 _drainQueueStep@resource://zotero/loader.jsm -> resource://zotero/bluebird/async.js:93:9 _drainQueue@resource://zotero/loader.jsm -> resource://zotero/bluebird/async.js:86:9 Async.prototype._drainQueues@resource://zotero/loader.jsm -> resource://zotero/bluebird/async.js:102:5 Async/this.drainQueues@resource://zotero/loader.jsm -> resource://zotero/bluebird/async.js:15:9 url => C:\Users\Chenran\Downloads\0Reading downloadAssociatedFiles => true

(5)(+0000000): Translate: Running handler 0 for error

(5)(+0000001): Translate: Running handler 0 for done


Update: To rule out some causes, I have remove the webpage items from the "0Reading" collection and make sure all items have attached PDFs. And the error is still there.

retorquere commented 2 years ago

New version is up which will log the paths. That should tell us which is the problem.

crliu95 commented 2 years ago

Thanks. With the new version, the debug log shows:

(3)(+0000002): Getting contents of C:\Users\Chenran\Zotero\translators\File Hierarchy.js

(4)(+0000005): Translate: Parsing code for File Hierarchy (86ffd88b-6f4e-4bec-a5be-839c1034beb2, 2021-12-30 10:58:20)

(3)(+0000002): Translate: Beginning translation with File Hierarchy

(3)(+0000000): Translate: File hierarchy: collections: {"VB4HPZAC":"Test"}

(5)(+0000004): Translate: Running handler 0 for itemDone

(3)(+0000001): Translate: File hierarchy: "Liu et al_2020_A Practical Guide to Counterfactual Estimators for Causal Inference with.pdf"

(5)(+0000005): Translate: Running handler 0 for itemDone

(3)(+0000000): Translate: File hierarchy: "Athey_Imbens_2017_The State of Applied Econometrics.pdf"

(5)(+0000004): Translate: Running handler 0 for itemDone

(3)(+0000000): Translate: File hierarchy: "Jensen_Oster_2009_Quarterly Journal of Economics_The Power of TV.pdf"

(5)(+0000005): Translate: Running handler 0 for itemDone

(3)(+0000000): Translate: File hierarchy: "Deshpande_Li_2019_Who Is Screened Out.pdf"

(5)(+0000003): Translate: Running handler 0 for itemDone

(3)(+0000000): Translate: File hierarchy: "Gentzkow_2006_Television and Voter Turnout.pdf"

(5)(+0000004): Translate: Running handler 0 for itemDone

(3)(+0000000): Translate: File hierarchy: "Test\Minetti et al_2019_Financial Constraints, Firms' Supply Chains, and Internationalization.pdf"

(1)(+0000001): NS_ERROR_FILE_UNRECOGNIZED_PATH Exception: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.append] _attachmentToArray/attachmentArray.saveFile@chrome://zotero/content/xpcom/translation/translate_item.js:1131:52 save@chrome://zotero/content/xpcom/translation/translate_firefox.js line 425 > eval:71:17 doExport@chrome://zotero/content/xpcom/translation/translate_firefox.js line 425 > eval:83:9 rest@chrome://zotero/content/xpcom/translation/translate.js:1356:28 Zotero.Translate.Base.prototype._translateTranslatorLoaded</<@chrome://zotero/content/xpcom/translation/translate.js:1346:37

(2)(+0000000): Translate: Translation using File Hierarchy failed: [Exception... "Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.append]" nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)" location: "JS frame :: chrome://zotero/content/xpcom/translation/translate_item.js :: _attachmentToArray/attachmentArray.saveFile :: line 1131" data: no] _attachmentToArray/attachmentArray.saveFile@chrome://zotero/content/xpcom/translation/translate_item.js:1131:52 save@chrome://zotero/content/xpcom/translation/translate_firefox.js line 425 > eval:71:17 doExport@chrome://zotero/content/xpcom/translation/translate_firefox.js line 425 > eval:83:9 rest@chrome://zotero/content/xpcom/translation/translate.js:1356:28 Zotero.Translate.Base.prototype._translateTranslatorLoaded</<@chrome://zotero/content/xpcom/translation/translate.js:1346:37 tryCatcher@resource://zotero/loader.jsm -> resource://zotero/bluebird/util.js:16:16 module.exports/Promise.prototype._settlePromiseFromHandler@resource://zotero/loader.jsm -> resource://zotero/bluebird/promise.js:547:13 module.exports/Promise.prototype._settlePromise@resource://zotero/loader.jsm -> resource://zotero/bluebird/promise.js:604:13 module.exports/Promise.prototype._settlePromise0@resource://zotero/loader.jsm -> resource://zotero/bluebird/promise.js:649:5 module.exports/Promise.prototype._settlePromises@resource://zotero/loader.jsm -> resource://zotero/bluebird/promise.js:729:13 _drainQueueStep@resource://zotero/loader.jsm -> resource://zotero/bluebird/async.js:93:9 _drainQueue@resource://zotero/loader.jsm -> resource://zotero/bluebird/async.js:86:9 Async.prototype._drainQueues@resource://zotero/loader.jsm -> resource://zotero/bluebird/async.js:102:5 Async/this.drainQueues@resource://zotero/loader.jsm -> resource://zotero/bluebird/async.js:15:9 url => C:\Users\Chenran\Downloads\0Reading downloadAssociatedFiles => true

It seems that the process gets stuck with the item in the subcollection. I am wondering whether the "\" in the path is the cause, which is not that compatible with Window file system.

retorquere commented 2 years ago

I'll try with a forward slash when I get home, but the backward slash is the windows directory separator. It's the only platform that uses it. Try it in a cmd shell.

crliu95 commented 2 years ago

Sorry, I meant the double backward slash.

And, is this problem replicable in your system?

crliu95 commented 2 years ago

I know it is unlikely the case, but do we need to manually create leaf folders under the root folder, for exporting the items in the subcollections?

retorquere commented 2 years ago

Sorry, I meant the double backward slash.

That's just how you write a single backlash in javascript.

And, is this problem replicable in your system?

No, but I don't have access to a windows machine.

I know it is unlikely the case, but do we need to manually create leaf folders under the root folder, for exporting the items in the subcollections?

Nope, should not be required.

A new version is up that just uses a forward slash across all platforms.

crliu95 commented 2 years ago

@retorquere This version is perfect. Thanks a lot!!!

retorquere commented 2 years ago

Cool, thanks for the confirmation.