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

[Bug]: runImport silently fails to upload if init() is called without populating process.env.ACTUAL_DATA_DIR #4326

Open
1 task done
JasonWeinzierl opened this issue Feb 7, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@JasonWeinzierl
Copy link

Verified issue does not already exist?

  • I have searched and found no existing issue

What happened?

When trying to use @actual-app/api in Node.js to import data with runImport, the import can silently fail when finishing. Calling sync afterward will cause additional errors (something about the metadata.json being empty). This happened both on Windows 10 and macOS for me. Tracking down the problem led me to this:

  1. This does not log errors when upload fails:
    await cloudStorage.upload().catch(() => {});
  2. Downstream dependency better-sqlite3 was throwing an error here, but the error didn't include a filename so it wasn't obvious why it was throwing: https://github.com/WiseLibs/better-sqlite3/blob/ea9a0586d2daf4ec15f1fb5fcd8a618de6c1ceee/lib/methods/backup.js#L29
  3. When temporarily patching the sqlite library in my node_modules, I found that it was trying to backup a filename starting with 'undefined/...'. That led me to this:
    const name = `${process.env.ACTUAL_DATA_DIR}/backup-for-export-${uuidv4()}.db`;
  4. But since I was just writing a Node.js script and calling init({ dataDir: '/tmp' }) instead of setting process.env.ACTUAL_DATA_DIR, that env var will always be empty.

Setting the env var fixed everything, but it seems like init({ dataDir: ... }) should also be supported.

How can we reproduce the issue?

import * as actual from '@actual-app/api';

async function importAllToNewBudget() {
    await actual.init({
        dataDir: '/tmp',
        serverURL: '<snip>',
        password: '<snip>',
    });

    const budgetName = new Date().toISOString();
    // No budget gets uploaded.
    await actual.runImport(budgetName, () => {});

    // These cause additional errors.
    await actual.sync();
    await actual.shutdown();
}

Where are you hosting Actual?

Locally via Yarn

What browsers are you seeing the problem on?

No response

Operating System

Windows 10

@JasonWeinzierl JasonWeinzierl added the bug Something isn't working label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant