"Code promise is not resolved in noWait mode"

146 views
Skip to first unread message

Emiliano Heyns

unread,
Nov 29, 2017, 12:08:59 PM11/29/17
to zotero-dev
I have a BBT user who's getting errors because translators are not being updated; in his logs, I see "Code promise is not resolved in noWait mode". Any idea? I've not seen this before.

Emiliano Heyns

unread,
Jan 27, 2018, 1:56:25 PM1/27/18
to zotero-dev
On Wednesday, November 29, 2017 at 6:08:59 PM UTC+1, Emiliano Heyns wrote:
I have a BBT user who's getting errors because translators are not being updated; in his logs, I see "Code promise is not resolved in noWait mode". Any idea? I've not seen this before.

I have another user who has this error (https://github.com/retorquere/zotero-better-bibtex/issues/893) which seems to interfere with the quick-copy handling. Any insights would be much appreciated -- I don't know where in Zotero this happens, nor do I know a likely cause.

Emiliano Heyns

unread,
Jan 22, 2022, 4:04:18 PMJan 22
to zotero-dev
I'm hitting this problem again, reproducibly. I do a Zotero.Translators.reinit(), but this does not seem to be enough. No idea what else I can do.

Emiliano Heyns

unread,
Jan 23, 2022, 1:38:57 PMJan 23
to zotero-dev
I don't know how the code-caching of Zotero works. I'm trying to enter the BBT translators into the cache to prevent the noWait problem.

Emiliano Heyns

unread,
Jan 26, 2022, 4:14:18 PMJan 26
to zotero-dev
I'm trawling through the Zotero sources, but I have not been able to find a way to make codePromise = translator.getCode() from translate.js return a pre-resolved promise. I could really use some help here.

Dan Stillman

unread,
Feb 22, 2022, 10:02:33 PMFeb 22
to zoter...@googlegroups.com
On 1/26/22 4:14 PM, Emiliano Heyns wrote:
> I'm trawling through the Zotero sources, but I have not been able to
> find a way to make codePromise = translator.getCode() from
> translate.js return a pre-resolved promise. I could really use some
> help here.

The .code property of the loaded translator needs to be populated. You
can do that by pre-calling getCodeForTranslator() once with
translator.cacheCode set to true, as the Quick Copy code does:

https://github.com/zotero/zotero/blob/1743360de75beb30ef24db61b6e418de08c63c02/chrome/content/zotero/xpcom/quickCopy.js#L336-L349

Emiliano Heyns

unread,
Feb 23, 2022, 6:18:59 AMFeb 23
to zotero-dev
That throws an

Error: TypeError: Zotero.Translators.getCodeForTranslator is not a function

for me

Emiliano Heyns

unread,
Feb 23, 2022, 6:51:55 AMFeb 23
to zotero-dev
I can call get and reinit on Zotero.Translators, but just before I try to call getCodeForTranslators, these are the properties on Zotero.Translators: ["init","reinit","load","loadFromFile","get","getAllForType","getAll","getWebTranslatorsForLocation","getSearchURIs","getImportTranslatorsForLocation","getFileNameFromLabel","getTranslatorsDirectory","save","cacheInDB","makeTranslatorProvider"]

Emiliano Heyns

unread,
Feb 23, 2022, 6:57:16 AMFeb 23
to zotero-dev
getCodeForTranslator seems to only exist in the beta.

Emiliano Heyns

unread,
Feb 23, 2022, 10:05:54 AMFeb 23
to zotero-dev
Should I expect this

new Zotero.Translator({...header, cacheCode: true, code })

to cache the code for the non-beta? It does seem to work.

Emiliano Heyns

unread,
Feb 23, 2022, 4:40:37 PMFeb 23
to zotero-dev
I have one user where I consistently get what seems to me a conflicting result from `Zotero.Translators.get` (Zotero 5.0.96.3 on Linux); `header` is a translator header JSON object;

const destFile = Zotero.getTranslatorsDirectory()
destFile.append(`${header.label}.js`)
const exists = destFile.exists()
const installed = Zotero.Translators.get(header.translatorID)

with `exists` always being true, but `installed` always being `false`. We have verified the BBT translators (which is what I'm testing for) do exist prior to start. Any idea? I cannot reproduce this myself.

adoma...@gmail.com

unread,
Feb 24, 2022, 7:19:16 AMFeb 24
to zotero-dev
Can you post some links to your code that's responsible for handling this? There have indeed been some translation code changes between Zotero 5 and the beta, so that's likely the cause of the issue. Hard to advise without seeing the code.

Emiliano Heyns

unread,
Feb 24, 2022, 7:36:00 AMFeb 24
to zotero-dev
It is this part:


Given that the translators exist in the translators directory before start, I would expect (and usually see, just not for this user) Zotero.Translators.get(header.translatorID) to return non-false

adoma...@gmail.com

unread,
Feb 24, 2022, 7:51:38 AMFeb 24
to zotero-dev
`Zotero.Translators.save()` only stores the files in the translator folder. You need to call `Translators.reinit` first (which I see you do in your own `init()` function) and then call getCodeForTranslator for all the translators that will need to have preloaded code. You should only call getCodeForTranslators() for translators that actually need the code available in noWait mode (which is primarily for things like drag-and-drop, since no async function calls are allowed to set drag and drop cntents). You can do this at a similar point in the code as we do for quickCopy - on init for the selected translator, and then on translator changes.

Emiliano Heyns

unread,
Feb 24, 2022, 8:02:48 AMFeb 24
to zotero-dev
That's what I'm trying to achieve, but for this particular user I always get false for Zoterro.Translators.get, which I interpret as "does not exist yet". I can test for file existence, but that seems like the wrong approach.

adoma...@gmail.com

unread,
Feb 24, 2022, 8:04:25 AMFeb 24
to zotero-dev
Is that test code being ran after Zotero.Translators.init() had finished running?

Emiliano Heyns

unread,
Feb 24, 2022, 8:10:21 AMFeb 24
to zotero-dev
Not explicitly -- I am waiting for schemaUpdatePromise. Is there something I can await for the translators.init?

adoma...@gmail.com

unread,
Feb 24, 2022, 8:13:01 AMFeb 24
to zotero-dev
You can await `Zotero.Translators.init()` itself, which will return a promise that is either already resolved or will resolve when translators have been initialized.

Emiliano Heyns

unread,
Feb 24, 2022, 8:13:23 AMFeb 24
to zotero-dev
As far as I can tell this get returning false is unique to this user. I cannot reproduce this on the platforms I have access to (which includes Linux this user has)

Emiliano Heyns

unread,
Feb 24, 2022, 8:50:07 AMFeb 24
to zotero-dev
Looks like I can just await Zotero.Translators.init() before doing anything else?

adoma...@gmail.com

unread,
Feb 24, 2022, 9:06:18 AMFeb 24
to zotero-dev
Looks like I can just await Zotero.Translators.init() before doing anything else?

  Before doing anything with translators for sure, yes.

 
 

Emiliano Heyns

unread,
Feb 24, 2022, 9:44:13 AMFeb 24
to zotero-dev
That fixed it. Super. This has been a long-standing annoyance in BBT, happy that that is now gone. Thanks!

Emiliano Heyns

unread,
Jun 19, 2022, 6:51:59 AMJun 19
to zotero-dev
turns out the problem still exists. could really use some insight to fix this. the problem is a nuisance again because note-d&d runs translators.
Reply all
Reply to author
Forward
0 new messages