Make runtime diagnostics non-blocking and release 2.1.69
CI / verify (push) Canceled after 0s

This commit is contained in:
Sucukdeluxe committed 2026-10-18 02:51:48 +02:00
1 parent 9d96f67261
commit 1e289ee49b
9 files changed
+129 -78

No files matched your search

+20 -20
View File
@@ -44,8 +44,8 @@ function createCollectors(deps) {
return p;
}
function getSystemInfo() {
return { app: appInfo(), system: systemInfo(), agent: agentInfo() };
async function getSystemInfo() {
return { app: appInfo(), system: await systemInfo(), agent: agentInfo() };
}
function getConfigRedacted(args) {
@@ -65,7 +65,7 @@ function createCollectors(deps) {
return { section, note, config: _deepRedact(pick, secrets) };
}
function listLogs() {
async function listLogs() {
const paths = getAllLogPaths();
const dir = paths.logDir;
const files = [];
@@ -78,7 +78,7 @@ function createCollectors(deps) {
const fp = backup === 0 ? base : getRotatedLogPath(base, backup);
readableNames.add(path.basename(fp));
try {
const st = fs.statSync(fp);
const st = await fs.promises.stat(fp);
variants.push({ backup, sizeBytes: st.size, mtime: st.mtime.toISOString() });
} catch {}
}
@@ -86,26 +86,28 @@ function createCollectors(deps) {
}
let siblings = [];
try {
siblings = fs.readdirSync(dir)
siblings = (await fs.promises.readdir(dir))
.filter(f => /\.log(\.\d+)?$/i.test(f))
.filter(f => !readableNames.has(f));
siblings = siblings.map(f => {
const otherLogs = [];
for (const f of siblings) {
let size = 0, mtime = null;
try { const st = fs.statSync(path.join(dir, f)); size = st.size; mtime = st.mtime.toISOString(); } catch {}
return { name: f, readable: false, sizeBytes: size, mtime };
});
try { const st = await fs.promises.stat(path.join(dir, f)); size = st.size; mtime = st.mtime.toISOString(); } catch {}
otherLogs.push({ name: f, readable: false, sizeBytes: size, mtime });
}
siblings = otherLogs;
} catch {}
return { dir, files, otherLogs: siblings };
}
function readLog(args) {
async function readLog(args, context = {}) {
const a = args || {};
const name = a.name;
const p = _resolveLogPath(name, a.backup);
if (!p) return { ok: false, error: `unknown or non-readable log: ${name}` };
const tailKb = Math.min(Math.max(Number(a.tailKb) || 256, 1), 1024);
const raw = support.collectFile(p, name, tailKb * 1024);
let content = support.redactLogText(raw, _secrets());
const snapshot = await support.collectFileSnapshot(p, name, tailKb * 1024, { signal: context.signal });
let content = support.redactLogText(snapshot.text, _secrets());
let matchedLines;
if (a.grep && typeof a.grep === 'string' && a.grep.length <= 200) {
const terms = a.grep.split('|').map(s => s.trim().toLowerCase()).filter(Boolean);
@@ -118,19 +120,17 @@ function createCollectors(deps) {
content = lines.join('\n');
}
}
let sizeBytes = null;
try { sizeBytes = fs.statSync(p).size; } catch {}
return { name, path: p, sizeBytes, returnedBytes: Buffer.byteLength(content), tailKb, matchedLines, content };
return { name, path: p, sizeBytes: snapshot.sizeBytes, returnedBytes: Buffer.byteLength(content), tailKb, matchedLines, content };
}
function getAppEvents(args) {
async function getAppEvents(args, context = {}) {
const limit = Math.min(Math.max(Number(args && args.limit) || 50, 1), 500);
const out = [];
const secrets = _secrets();
for (const name of ['crash', 'debug']) {
const p = _resolveLogPath(name);
if (!p) continue;
const raw = support.redactLogText(support.collectFile(p, name, 256 * 1024), secrets);
const raw = support.redactLogText(await support.collectFile(p, name, 256 * 1024, { signal: context.signal }), secrets);
const lines = raw.split('\n').filter(l => l.trim() && !l.startsWith('==='));
for (const line of lines.slice(-limit)) out.push({ source: name, text: line });
}
@@ -250,7 +250,7 @@ function createCollectors(deps) {
};
}
function serverHealth(args) {
async function serverHealth(args) {
const a = args || {};
const errorLimit = Math.min(Math.max(Number(a.errorLimit) || 20, 1), 200);
const errArgs = Number.isFinite(a.errorSinceMs) ? { sinceMs: a.errorSinceMs, limit: errorLimit } : { limit: errorLimit };
@@ -261,13 +261,13 @@ function createCollectors(deps) {
if (queue.source === 'persisted' && queue.stale) warnings.push('queue state is from the persisted snapshot (may lag live state; UploadManager not introspected in this build).');
if (errors.total > 0) warnings.push(`${errors.total} non-success result(s) in the error window.`);
return {
server: getSystemInfo(),
server: await getSystemInfo(),
queue,
recentBatches: history.batches,
perHoster: history.perHoster,
errors,
hosters: getHealth(),
logs: listLogs(),
logs: await listLogs(),
warnings
};
}