mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 16:34:33 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -23,7 +23,9 @@ const writesByPath = new Map<string, Promise<void>>();
|
||||
|
||||
async function pruneIfNeeded(filePath: string, opts: { maxBytes: number; keepLines: number }) {
|
||||
const stat = await fs.stat(filePath).catch(() => null);
|
||||
if (!stat || stat.size <= opts.maxBytes) return;
|
||||
if (!stat || stat.size <= opts.maxBytes) {
|
||||
return;
|
||||
}
|
||||
|
||||
const raw = await fs.readFile(filePath, "utf-8").catch(() => "");
|
||||
const lines = raw
|
||||
@@ -64,19 +66,33 @@ export async function readCronRunLogEntries(
|
||||
const limit = Math.max(1, Math.min(5000, Math.floor(opts?.limit ?? 200)));
|
||||
const jobId = opts?.jobId?.trim() || undefined;
|
||||
const raw = await fs.readFile(path.resolve(filePath), "utf-8").catch(() => "");
|
||||
if (!raw.trim()) return [];
|
||||
if (!raw.trim()) {
|
||||
return [];
|
||||
}
|
||||
const parsed: CronRunLogEntry[] = [];
|
||||
const lines = raw.split("\n");
|
||||
for (let i = lines.length - 1; i >= 0 && parsed.length < limit; i--) {
|
||||
const line = lines[i]?.trim();
|
||||
if (!line) continue;
|
||||
if (!line) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const obj = JSON.parse(line) as Partial<CronRunLogEntry> | null;
|
||||
if (!obj || typeof obj !== "object") continue;
|
||||
if (obj.action !== "finished") continue;
|
||||
if (typeof obj.jobId !== "string" || obj.jobId.trim().length === 0) continue;
|
||||
if (typeof obj.ts !== "number" || !Number.isFinite(obj.ts)) continue;
|
||||
if (jobId && obj.jobId !== jobId) continue;
|
||||
if (!obj || typeof obj !== "object") {
|
||||
continue;
|
||||
}
|
||||
if (obj.action !== "finished") {
|
||||
continue;
|
||||
}
|
||||
if (typeof obj.jobId !== "string" || obj.jobId.trim().length === 0) {
|
||||
continue;
|
||||
}
|
||||
if (typeof obj.ts !== "number" || !Number.isFinite(obj.ts)) {
|
||||
continue;
|
||||
}
|
||||
if (jobId && obj.jobId !== jobId) {
|
||||
continue;
|
||||
}
|
||||
parsed.push(obj as CronRunLogEntry);
|
||||
} catch {
|
||||
// ignore invalid lines
|
||||
|
||||
Reference in New Issue
Block a user