psybers / actual-helpers

Apache License 2.0
23 stars 5 forks source link

Promise rejection when running track-investments #1

Closed faultoverload closed 1 month ago

faultoverload commented 3 months ago

I have been able to run the sync-bank,kbb, and zestimate scripts but I get this error with the track-investments.

I have one SimpleFIN synced account that I added "calcInvestment" to the notes.

connect
open file
Loaded spreadsheet from cache (14787 items)
Syncing since 2024-07-01T19:53:43.236Z-0000-a172f8989c62ff17 2 (attempt: 0)
Got messages from server 1
node:internal/process/promises:389
      new UnhandledPromiseRejection(reason);
      ^

UnhandledPromiseRejection: 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(). The promise rejected with the reason "#<Object>".
    at throwUnhandledRejectionsMode (node:internal/process/promises:389:7)
    at processPromiseRejections (node:internal/process/promises:470:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:32) {
  code: 'ERR_UNHANDLED_REJECTION'
}

Node.js v22.3.0
psybers commented 3 months ago

Can you try running node --trace-warnings track-investments.js to see if we get a useful stack trace?

faultoverload commented 3 months ago

That doesn't appear to have changed the output.

connect
open file
Loaded spreadsheet from cache (14787 items)
Syncing since 2024-07-01T19:56:28.349Z-0000-a172f8989c62ff17 0 (attempt: 0)
Got messages from server 1
node:internal/process/promises:389
      new UnhandledPromiseRejection(reason);
      ^

UnhandledPromiseRejection: 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(). The promise rejected with the reason "#<Object>".
    at throwUnhandledRejectionsMode (node:internal/process/promises:389:7)
    at processPromiseRejections (node:internal/process/promises:470:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:32) {
  code: 'ERR_UNHANDLED_REJECTION'
}

Node.js v22.3.0
psybers commented 3 months ago

@faultoverload I also updated the code to add more logging, could you pull and see if that gives a trace?

psybers commented 2 months ago

@faultoverload This might have been because you renamed the account. Did you rename the account from what SimpleFIN originally provided?

I hit that issue with one of my accounts. I fixed the crash, but unfortunately for now I can't get it to work. There is a PR in Actual that needs merged before this can work with accounts that were renamed.

faultoverload commented 2 months ago

Hey, I don't think I renamed anything in simplefin but the account name in Actual doesn't match with Simplefin.

I tried running the updated code you added but I was actually getting errors for all the scripts after that. Tested on my local install as well as a docker container running node.

On Wed, Jul 10, 2024, 7:50 PM Robert Dyer @.***> wrote:

@faultoverload https://github.com/faultoverload This might have been because you renamed the account. Did you rename the account from what SimpleFIN originally provided?

I hit that issue with one of my accounts. I fixed the crash, but unfortunately for now I can't get it to work. There is a PR in Actual that needs merged before this can work with accounts that were renamed.

— Reply to this email directly, view it on GitHub https://github.com/psybers/actual-helpers/issues/1#issuecomment-2221722817, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKIMSHFWUPF4V7TBU6O3MGTZLXCEHAVCNFSM6AAAAABKGGJLU2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRRG4ZDEOBRG4 . You are receiving this because you were mentioned.Message ID: @.***>

psybers commented 2 months ago

@faultoverload Did you update the packages, npm update? It needs the latest Actual API.

But yes if the name does not match that was why you were previously getting an error. As of right now, the error should be silenced but it will not update it. After one of my PRs is merged in and a new Actual release happens I'll update these scripts and it should start working.

faultoverload commented 1 month ago

Hey so Im back and running the newest version of Actual as well as this project.

I have a docker container built with this Dockerfile

# Use an official Node.js runtime as a parent image
FROM node:22

# Set the working directory in the container
WORKDIR /usr/src/app

# Create the cache directory
RUN mkdir -p ./cache

# Copy the current directory contents into the container at /usr/src/app
COPY . .

# Install any needed packages specified in package.json
RUN npm install

# Define environment variable
ENV NODE_ENV production

# Run the app when the container launches
ENTRYPOINT ["tail", "-f", "/dev/null"]

I then start up that container and run a command with docker exec like this.

docker exec gallant_khorana node track-investments.js

That outputs this where is seems to hang. I was able to again run the sync-banks, kbb, and zestimate scripts without error.

connect
open file
Loaded spreadsheet from cache (15532 items)
Syncing since 2024-08-09T18:17:27.952Z-000F-96e923fb8c3f104b 0 (attempt: 0)
Got messages from server 1
Unhandled Rejection at: Promise Promise {
  <rejected> {
    type: 'APIError',
    message: 'Creating a category: groupId is required',
    meta: undefined
  }
} reason: {
  type: 'APIError',
  message: 'Creating a category: groupId is required',
  meta: undefined
}
undefined
Unhandled Rejection at: Promise Promise {
  <rejected> {
    type: 'APIError',
    message: 'Creating a category: groupId is required',
    meta: undefined
  }
} reason: {
  type: 'APIError',
  message: 'Creating a category: groupId is required',
  meta: undefined
}
undefined

My config in actual just to confirm this is correct as well.

image

psybers commented 1 month ago

@faultoverload You need to run npm update to get the latest Actual API. Otherwise, you get APIErrors because the API you are using does not match the server's API.

Since you are doing it via Docker images, you will need to rebuild the Docker image.

psybers commented 1 month ago

Ok actually this might be my code. It looks like the API was changed to require a category ID and I do not provide one. Let me try fixing this.

psybers commented 1 month ago

@faultoverload If you can, please pull the latest. This should fix your issues. You might need to set some new environment variables in your .env file:

# optional, name of the payee for added interest transactions
INVESTMENT_PAYEE_NAME="Investment"
# optional, name of the cateogry group for added investment tracking transactions
INVESTMENT_CATEGORY_GROUP_NAME="Income"
# optional, name of the category for added investment tracking transactions
INVESTMENT_CATEGORY_NAME="Investment"
faultoverload commented 1 month ago

I pulled your new code and rebuilt the container and after a bit of fussing about it appears to be working correctly.

Is it possible to allow us to declare the SimpleFIN token through the .var file because having to type it into the console during the first run breaks the automation with Docker.

psybers commented 1 month ago

The token is only good for one use, so no matter how you do it you must save the result. You could mount the path into your Docker image, so that the file that saves the login token is persisted.

I'm going to close this issue since you got it working.

psybers commented 1 month ago

That said I can maybe get it so you can stuff the resulting token into an ENV...

psybers commented 1 month ago

Pull the latest. Now when you give it your setup token it will print the credentials (and store to the file). If you want, you can stick that into an ENV and it will use that instead of the file.

faultoverload commented 1 month ago

Thanks! That did the trick. I submitted my code as a pull request in case anyone else wants to use Docker for this project.