Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors: 'e' is of type 'unknown' & Type 'unknown' is not assignable to type 'string | null' #3

Open
4 tasks done
joshuawagner opened this issue Jun 24, 2023 · 6 comments

Comments

@joshuawagner
Copy link

Hi, I'm almost done with my dissertation! Thanks for your help over the years. Do you have a patreon or paypal so I can send a little appreciation your way?

I'm trying to get zotero-sync-bookends up and running again on my M1 mac after a while. I don't know what happened to my previous setup because the api key and bookends db name were both at default in my local repo. Anyways...starting over.

What I've done so far

reading through the readme and following instructions**

  • add path to ENV variable so that zotero-sync-bookends can find node library
    • cd ../usr/bin/
    • export PATH=/Users/josh/node_modules:PATH
    • export PATH=/Users/josh/Documents/Bookends:$PATH // not sure if this is necessary but I can't see how else it knows how to find the bookends db

created a new key in Zotero portal online

The following links are accessible:

edited lines 29 and 30 in /Users/josh/node_modules/@cboulanger/zotero-sync-bookends/test.ts

  • zotero_api_key = "loremipsum";
  • bookends_db_name = "2022-09-21 bookends db";

install node packages

  • cd /Users/josh/node_modules/@cboulanger/zotero-sync-bookends
  • npm install

run!

  • npm test

Errors

I get 6 errors from /src/index.ts.

> @cboulanger/zotero-sync-bookends@2.1.1 test
> tsc && npx ts-node test.ts

src/index.ts:105:7 - error TS18046: 'e' is of type 'unknown'.

105       e.lastJxaCmd = cmd;
          ~

src/index.ts:162:11 - error TS18046: 'e' is of type 'unknown'.

162       if (e.message.includes("-1728")) {
              ~

src/index.ts:313:11 - error TS18046: 'e' is of type 'unknown'.

313       if (e.message.includes("-1728")) {
              ~

src/index.ts:329:11 - error TS18046: 'e' is of type 'unknown'.

329       if (e.message.includes("-1728")) {
              ~

src/index.ts:378:17 - error TS18046: 'e' is of type 'unknown'.

378             if (e.message.includes("-1712")) {
                    ~

src/index.ts:380:15 - error TS2322: Type 'unknown' is not assignable to type 'string | null'.

380               error = e;
                  ~~~~~


Found 6 errors in the same file, starting at: src/index.ts:105

Index.ts

Here's the section of index.ts that I think it's referencing in the error:

const citekey = this.generateCitekey(item);
switch (item.itemType) {
case "attachment":
case "note":
break;
default: {
let tries = 0;
let error: null | string = null;
while(tries++ < this.maxTries) {
try {
const storedData = await this.getPublicationByCitekey(citekey)
const data = this.zoteroToBookends(item, citekey);
if (storedData) {
const changedProperties = Object.keys(data).filter( key => data[key] !== storedData[key]);
if (changedProperties.length) {
// update if item has changed
const changedData: {[key: string]: string} = {};
changedProperties.forEach(key => changedData[key] = data[key]);
this.logVerbose(`Updating item '${data.title}', properties ${Object.keys(changedData).join(",")}`);
await this.updatePublication(Number(storedData.id), changedData);
}
} else {
this.logVerbose(`Adding item '${data.title}' ...`);
await this.addPublication(data);
}
// success!
error = null;
break; // break while-loop
} catch (e) {
if (e.message.includes("-1712")) {
// timeout, try again
error = e;
continue;
}
// try to save metadata, including last index, ignoring any errors
try {
await this.saveMetadata();
} catch (e) {}
throw e;
}
}
if (error) {
throw error;
}
this.lastIndex++;
// save metadata every 10 items so that this doesn't slow things down too much
if (this.lastIndex % 10 === 0) {
await this.saveMetadata();
}
}

@cboulanger
Copy link
Owner

cboulanger commented Jun 30, 2023

Hi Joshua - I quickly want to respond to let you know I've seen the issue - I'm a bit short on time at the moment but I hope I can be of help. My gut feeling is that it is a compatibility issue - I haven't updated the code in such a long time that it might no longer work with current node or jsx versions. I'l have to try it myself and will do that as soon as I find a minute.

In the meantime, can you tell me what NodeJS and Mac versions you are working on?

Thanks for your offer - I just setting up GitHub Sponsors (not active yet) and maybe that's a way, otherwise I am happy to give you my paypal address.

@joshuawagner
Copy link
Author

Sure, paypal is great.

I'm on MacOS 13.4.1 on an M1.
I was on NodeJS 18.9.0 but I updated to the 18.6.1 (LTS) and I get the same errors.

@cboulanger
Copy link
Owner

Thanks - I hope I can have a look tonight. I've enabled GitHub Sponsoring, if that works for you, or my PayPal is c.boulanger@gmx.de ... Very much appreciated!

@cboulanger
Copy link
Owner

I tried it with v18.16.1 and v20.3.1 (the latest versions of v18 and v20 as provided by nvm) and both worked. I am on MacOS 13.2.1 (Intel) I wonder if Apple Silicon might be a problem. Do you have an older Mac to try it on?

@cboulanger
Copy link
Owner

And maybe as a workaround, adapt line 378 like so:

if (e && e.message && e.message.includes("-1712")) { 

Does this help?

@joshuawagner
Copy link
Author

When I enter that change VS Code gives me as a tooltip:
20230721_062119-screenshot

These are the errors that I get when I npm test

src/index.ts:105:7 - error TS18046: 'e' is of type 'unknown'.

105       e.lastJxaCmd = cmd;
          ~

src/index.ts:162:11 - error TS18046: 'e' is of type 'unknown'.

162       if (e.message.includes("-1728")) {
              ~

src/index.ts:313:11 - error TS18046: 'e' is of type 'unknown'.

313       if (e.message.includes("-1728")) {
              ~

src/index.ts:329:11 - error TS18046: 'e' is of type 'unknown'.

329       if (e.message.includes("-1728")) {
              ~

src/index.ts:378:24 - error TS2339: Property 'message' does not exist on type '{}'.

378             if (e && e.message && e.message.includes("-1712")) {
                           ~~~~~~~

src/index.ts:378:37 - error TS2339: Property 'message' does not exist on type '{}'.

378             if (e && e.message && e.message.includes("-1712")) {
                                        ~~~~~~~

src/index.ts:380:15 - error TS2322: Type '{}' is not assignable to type 'string'.

380               error = e;
                  ~~~~~

Here are the error indicators.
20230721_062139-screenshot

I'll start from the top:
20230721_062709-screenshot

20230721_063730-screenshot

20230721_062905-screenshot

20230721_062953-screenshot

20230721_063100-screenshot

20230721_063133-screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants