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

Open
opened 2026-02-28 19:56:03 -06:00 by GiteaMirror · 1 comment
Owner

Originally created by @JasonWeinzierl on GitHub (Feb 7, 2025).

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: 5f1fadb7cc/packages/loot-core/src/server/api.ts (L322)
  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: ea9a0586d2/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: 5f1fadb7cc/packages/loot-core/src/platform/server/sqlite/index.electron.ts (L133)
  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

Originally created by @JasonWeinzierl on GitHub (Feb 7, 2025). ### Verified issue does not already exist? - [x] 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: https://github.com/actualbudget/actual/blob/5f1fadb7ccf804763f1bbdfa74ab7640ea909222/packages/loot-core/src/server/api.ts#L322 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: https://github.com/actualbudget/actual/blob/5f1fadb7ccf804763f1bbdfa74ab7640ea909222/packages/loot-core/src/platform/server/sqlite/index.electron.ts#L133 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? ```ts 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
GiteaMirror added the bugAPI labels 2026-02-28 19:56:03 -06:00
Author
Owner

@PhKP commented on GitHub (Mar 17, 2025):

+1
I also experience this issue.

@PhKP commented on GitHub (Mar 17, 2025): +1 I also experience this issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#1839