actualbudget / actual

A local-first personal finance app
https://actualbudget.org
MIT License
12.51k stars 954 forks source link

[Bug]: Desktop Client no longer able to export budget files #2907

Open youngcw opened 1 week ago

youngcw commented 1 week ago

Verified issue does not already exist?

What happened?

I can no longer export budget files using either the linux appimage or flatpak. I haven't tested either windows or mac to see if they have the same issue.

Where are you hosting Actual?

None

What browsers are you seeing the problem on?

Desktop App (Electron)

Operating System

Linux

MatissJanis commented 1 week ago

Broken on Mac too (using v24.6.0 release)

MatissJanis commented 1 week ago

Did a bit of investigation here.

The error: unable to open database file.

Comes from SQLite. My current hypothesis is that the backend is no longer able to open the local sqlite file after upgrade of Electron (possibly permission issue?).

Breaking function: https://github.com/actualbudget/actual/blob/5b1a730f111d6a670d336d573bddb95c2a1e7e96/packages/loot-core/src/server/cloud-storage.ts#L119

My investigation here stops at this point. If anyone has time/ability - feel free to pick it up.

youngcw commented 1 week ago

So I tried reverting #2763 and I could export the file. That went back to an older electron version that is no longer supported. I also noticed that the newer version of electron that that PR set lists node v20 as the version to use. I don't know if updating the project to node v20 would help or not.

Looks to me like better-sqlite v9.6.0 should work fine. It seems to support down to node v16 until version v10 which supports v18 still.

MikesGlitch commented 1 week ago

It works on Windows.

The issue is related to this: https://github.com/electron/electron/issues/42621

It fails at:

const fileLocation = dialog.showSaveDialogSync({ title, defaultPath

The async variant of the same function works - I'll put a PR in for that so we don't have to wait for a fix to Electron

youngcw commented 1 week ago

2925 only fixed linux but mac is still broken.

MikesGlitch commented 1 week ago

Cool. I don't have a mac so I'd struggle to fix that one.

It looks like a sqlite error - the bettersqlite upgraded to the latest minor version, but I'd have expected that to fail for everything. I can't see anything that could have caused that here: https://github.com/WiseLibs/better-sqlite3/compare/v9.3.0...v9.6.0

Things we could check:

I found this, which is suggesting it may be permissions related - something about the app needing full disk access to write to the disk: https://stackoverflow.com/questions/67430680/sqlite3-operationalerror-unable-to-open-database-file-on-mac-os-external-hard

MatissJanis commented 1 week ago

Thanks! Testing using the latest master:

Does it fail when importing a budget

✅ importing works as expected

Does it fail when exporting transactions (from an account)

✅ exporting single account transactions works

Does it fail when running the unpackaged version? E.g. Running yarn start:desktop

✅ no failures when running un-packaged version

🔴 giving the app "full disk access" permissions (manually) did not fix the issue

MikesGlitch commented 1 week ago

Cool, so that narrows it down then. We had two separate issues,

It's weird that it works on unpackaged version but not the packaged version. If it was packaged locally on the mac, would that fail I wonder...

It's probably something around here: https://github.com/actualbudget/actual/blob/5b1a730f111d6a670d336d573bddb95c2a1e7e96/packages/loot-core/src/server/cloud-storage.ts#L143

Would need to check the values of rawDbContent to see if it received the content

Another possibility is the openDatabase implementation is wrong - it's slightly different from the web one.

Electron: https://github.com/actualbudget/actual/blob/48f5880f1dc260ff8a791cdb87aa4ce947df54f6/packages/loot-core/src/platform/server/sqlite/index.electron.ts#L102

Web: https://github.com/actualbudget/actual/blob/48f5880f1dc260ff8a791cdb87aa4ce947df54f6/packages/loot-core/src/platform/server/sqlite/index.web.ts#L162

If the problem lies here, it must have always failed on Mac.

Do we know if this was working on Mac before we did the Electron update?

MatissJanis commented 1 week ago

Quick update: went 5 months back in history to try and find offending commit. No luck. And I'm absolutely sure I've tried doing an export in the last 5 months and it worked.

Which leads me to believe this might be something new after upgrading the OS.

xinomoreno commented 3 days ago

0 experience with typescript, node, electron....trying to learn. Maybe I'm doing something wrong and this is not a good trail. I built the electron packaged app with build:desktop on a M1 mac and then executed the app. I wished i could have tried to export database but couldn't even open it. So I tried to lldb the app, got this exception: ( [Exception] Error: dlopen(/var/folders/nz/zy2d1fbs7fsd7kg550fzw2tc0000gn/T/.com.actualbudget.actual.eknH2s, 0x0001): tried: '/var/folders/nz/zy2d1fbs7fsd7kg550fzw2tc0000gn/T/.com.actualbudget.actual.eknH2s' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/var/folders/nz/zy2d1fbs7fsd7kg550fzw2tc0000gn/T/.com.actualbudget.actual.eknH2s' (no such file), '/var/folders/nz/zy2d1fbs7fsd7kg550fzw2tc0000gn/T/.com.actualbudget.actual.eknH2s' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/private/var/folders/nz/zy2d1fbs7fsd7kg550fzw2tc0000gn/T/.com.actualbudget.actual.eknH2s' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/nz/zy2d1fbs7fsd7kg550fzw2tc0000gn/T/.com.actualbudget.actual.eknH2s' (no such file), '/private/var/folders/nz/zy2d1fbs7fsd7kg550fzw2tc0000gn/T/.com.actualbudget.actual.eknH2s' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')) at process.func [as dlopen] (node:electron/js2c/node_init:2:2214) at Module._extensions..node (node:internal/modules/cjs/loader:1489:18) at Object.func [as .node] (node:electron/js2c/node_init:2:2441) at Module.load (node:internal/modules/cjs/loader:1214:32) at Module._load (node:internal/modules/cjs/loader:1030:12) at c._load (node:electron/js2c/node_init:2:13672) at Module.require (node:internal/modules/cjs/loader:1242:19) at require (node:internal/modules/helpers:176:18) at bindings (/Users/miguelcalduchnos/dev/actual/packages/desktop-electron/dist/Actual.app/Contents/Resources/app.asar/node_modules/bindings/bindings.js:112:48) at new Database (/Users/miguelcalduchnos/dev/actual/packages/desktop-electron/dist/Actual.app/Contents/Resources/app.asar/node_modules/better-sqlite3/lib/database.js:48:64) { code: 'ERR_DLOPEN_FAILED' }

Could it be related to the same export issue?

MikesGlitch commented 3 days ago

mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')

Hey, try this https://github.com/WiseLibs/better-sqlite3/issues/968#issuecomment-1465320102

xinomoreno commented 5 hours ago

Seems my problem was in the other direction, actual was x86 app and sqlite3 is arm as my node.js. So I built actual as arm64 and sorted it out. I could reproduce the issue with export but when executing with lldb, export works like a charm 😢