log.warn
This commit is contained in:
parent
e88f7fde36
commit
f64d4943ed
|
@ -38,28 +38,32 @@ export const logToDisk = (message: string) => {
|
||||||
log.info(`[rndr] ${message}`);
|
log.info(`[rndr] ${message}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const logError = (message: string, e?: unknown) => {
|
const messageWithError = (message: string, e?: unknown) => {
|
||||||
if (!e) {
|
if (!e) return message;
|
||||||
logError_(message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let es: string;
|
let es: string;
|
||||||
if (e instanceof Error) {
|
if (e instanceof Error) {
|
||||||
// In practice, we expect ourselves to be called with Error objects, so
|
// In practice, we expect ourselves to be called with Error objects, so
|
||||||
// this is the happy path so to say.
|
// this is the happy path so to say.
|
||||||
es = `${e.name}: ${e.message}\n${e.stack}`;
|
es = [`${e.name}: ${e.message}`, e.stack].filter((x) => x).join("\n");
|
||||||
} else {
|
} else {
|
||||||
// For the rest rare cases, use the default string serialization of e.
|
// For the rest rare cases, use the default string serialization of e.
|
||||||
es = String(e);
|
es = String(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
logError_(`${message}: ${es}`);
|
return `${message}: ${es}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const logError_ = (message: string) => {
|
const logError = (message: string, e?: unknown) => {
|
||||||
log.error(`[main] [error] ${message}`);
|
const m = `[error] ${messageWithError(message, e)}`;
|
||||||
console.error(`[error] ${message}`);
|
console.error(m);
|
||||||
|
log.error(`[main] ${m}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const logWarn = (message: string, e?: unknown) => {
|
||||||
|
const m = `[warn] ${messageWithError(message, e)}`;
|
||||||
|
console.error(m);
|
||||||
|
log.error(`[main] ${m}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const logInfo = (...params: unknown[]) => {
|
const logInfo = (...params: unknown[]) => {
|
||||||
|
@ -97,6 +101,11 @@ export default {
|
||||||
* console.
|
* console.
|
||||||
*/
|
*/
|
||||||
error: logError,
|
error: logError,
|
||||||
|
/**
|
||||||
|
* Sibling of {@link error}, with the same parameters and behaviour, except
|
||||||
|
* it gets prefixed with a warning instead of an error tag.
|
||||||
|
*/
|
||||||
|
warn: logWarn,
|
||||||
/**
|
/**
|
||||||
* Log a message.
|
* Log a message.
|
||||||
*
|
*
|
||||||
|
|
|
@ -3,6 +3,7 @@ import fs from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { existsSync } from "original-fs";
|
import { existsSync } from "original-fs";
|
||||||
import type { PendingUploads, ZipItem } from "../../types/ipc";
|
import type { PendingUploads, ZipItem } from "../../types/ipc";
|
||||||
|
import log from "../log";
|
||||||
import { uploadStatusStore } from "../stores/upload-status";
|
import { uploadStatusStore } from "../stores/upload-status";
|
||||||
|
|
||||||
export const listZipItems = async (zipPath: string): Promise<ZipItem[]> => {
|
export const listZipItems = async (zipPath: string): Promise<ZipItem[]> => {
|
||||||
|
@ -64,11 +65,16 @@ export const pendingUploads = async (): Promise<PendingUploads | undefined> => {
|
||||||
// file, but the dedup logic will kick in at that point so no harm will come
|
// file, but the dedup logic will kick in at that point so no harm will come
|
||||||
// of it.
|
// of it.
|
||||||
if (allZipItems === undefined) {
|
if (allZipItems === undefined) {
|
||||||
const allZipPaths = uploadStatusStore.get("filePaths") ?? [];
|
const allZipPaths = uploadStatusStore.get("zipPaths") ?? [];
|
||||||
const zipPaths = allZipPaths.filter((f) => existsSync(f));
|
const zipPaths = allZipPaths.filter((f) => existsSync(f));
|
||||||
zipItems = [];
|
zipItems = [];
|
||||||
for (const zip of zipPaths)
|
for (const zip of zipPaths) {
|
||||||
zipItems = zipItems.concat(await listZipItems(zip));
|
try {
|
||||||
|
zipItems = zipItems.concat(await listZipItems(zip));
|
||||||
|
} catch (e) {
|
||||||
|
log.error("Ignoring items in malformed zip", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
zipItems = allZipItems.filter(([z]) => existsSync(z));
|
zipItems = allZipItems.filter(([z]) => existsSync(z));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue