Fix crash: state initialized before CFG is loaded

state.baseCurrency was set to CFG['currency-base'] at declaration time,
but CFG is only populated after await loadConfig(). Reading a property of
undefined throws synchronously, crashing the script before init() runs.
Move the assignment to after loadConfig() resolves in init().

https://claude.ai/code/session_014uUwDBtG5y5FuWcy5zqVD1
This commit is contained in:
Claude 2026-05-13 09:30:22 +00:00
parent e1292822f8
commit 156c76baae
No known key found for this signature in database

View file

@ -140,7 +140,7 @@ async function loadConfig() {
} }
// ========== STATE ========== // ========== STATE ==========
const state = { staff: '', periodFrom: '', periodTo: '', baseCurrency: CFG['currency-base'], fxRateMemory: {}, items: [], _grandTotal: 0 }; const state = { staff: '', periodFrom: '', periodTo: '', baseCurrency: '', fxRateMemory: {}, items: [], _grandTotal: 0 };
function newItem() { return { id: uid(), name: '', lines: [newLine()], _subtotal: 0 }; } function newItem() { return { id: uid(), name: '', lines: [newLine()], _subtotal: 0 }; }
function newLine() { function newLine() {
@ -848,6 +848,7 @@ async function onGenerate() {
async function init() { async function init() {
try { try {
await loadConfig(); await loadConfig();
state.baseCurrency = CFG['currency-base'];
state.items.push(newItem()); state.items.push(newItem());
render(); render();
} catch (e) { } catch (e) {