fix(nas): log swallowed filesystem errors instead of silently dropping them
nas-file-manager (21) and nas-financials-manager (9) had empty catch blocks that swallowed mkdir/write/rm/rename/stat/readdir failures with zero logging, making NAS issues undebuggable (violates the 'never silently swallow errors' rule). Added a contextual console.error to each real-failure catch (matching the existing service console.* pattern); control flow and return values unchanged. Left 3 ENOENT-as-expected catches (move/createFolder existence checks, symlink-traversal guard) as deliberate no-logs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,12 @@ class NasFinancialsManager {
|
||||
try {
|
||||
fs.mkdirSync(this.basePath, { recursive: true });
|
||||
return fs.statSync(this.basePath).isDirectory();
|
||||
} catch {
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"[nas-financials-manager] mkdir/stat failed for basePath:",
|
||||
this.basePath,
|
||||
err,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -44,7 +49,12 @@ class NasFinancialsManager {
|
||||
const monthPath = path.join(yearPath, monthDir);
|
||||
try {
|
||||
if (!fs.statSync(monthPath).isDirectory()) continue;
|
||||
} catch {
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"[nas-financials-manager] stat failed for monthPath:",
|
||||
monthPath,
|
||||
err,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const filePath = path.join(monthPath, safeName);
|
||||
@@ -53,8 +63,12 @@ class NasFinancialsManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// best effort
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"[nas-financials-manager] cleanIssuedInvoice failed for:",
|
||||
invoiceNumber,
|
||||
err,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +87,12 @@ class NasFinancialsManager {
|
||||
try {
|
||||
fs.writeFileSync(fullPath, pdfBuffer);
|
||||
return `${DIR_ISSUED}/${year}/${this.pad(month)}/${path.basename(fullPath)}`;
|
||||
} catch {
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"[nas-financials-manager] write failed for issued invoice:",
|
||||
fullPath,
|
||||
err,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -86,7 +105,12 @@ class NasFinancialsManager {
|
||||
try {
|
||||
const data = fs.readFileSync(fullPath);
|
||||
return { data, fileName: path.basename(fullPath) };
|
||||
} catch {
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"[nas-financials-manager] read failed for issued invoice:",
|
||||
fullPath,
|
||||
err,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -97,7 +121,12 @@ class NasFinancialsManager {
|
||||
try {
|
||||
fs.unlinkSync(fullPath);
|
||||
return true;
|
||||
} catch {
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"[nas-financials-manager] delete failed for issued invoice:",
|
||||
fullPath,
|
||||
err,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -148,7 +177,12 @@ class NasFinancialsManager {
|
||||
try {
|
||||
const data = fs.readFileSync(fullPath);
|
||||
return { data, fileName: path.basename(fullPath) };
|
||||
} catch {
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"[nas-financials-manager] read failed for received invoice:",
|
||||
fullPath,
|
||||
err,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -160,7 +194,12 @@ class NasFinancialsManager {
|
||||
try {
|
||||
fs.unlinkSync(fullPath);
|
||||
return true;
|
||||
} catch {
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"[nas-financials-manager] delete failed for received invoice:",
|
||||
fullPath,
|
||||
err,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -181,7 +220,12 @@ class NasFinancialsManager {
|
||||
try {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
return dirPath;
|
||||
} catch {
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"[nas-financials-manager] mkdir failed for path:",
|
||||
dirPath,
|
||||
err,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user