log.warn
This commit is contained in:
parent
e88f7fde36
commit
f64d4943ed
2 changed files with 28 additions and 13 deletions
|
@ -38,28 +38,32 @@ export const logToDisk = (message: string) => {
|
|||
log.info(`[rndr] ${message}`);
|
||||
};
|
||||
|
||||
const logError = (message: string, e?: unknown) => {
|
||||
if (!e) {
|
||||
logError_(message);
|
||||
return;
|
||||
}
|
||||
const messageWithError = (message: string, e?: unknown) => {
|
||||
if (!e) return message;
|
||||
|
||||
let es: string;
|
||||
if (e instanceof Error) {
|
||||
// In practice, we expect ourselves to be called with Error objects, so
|
||||
// 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 {
|
||||
// For the rest rare cases, use the default string serialization of e.
|
||||
es = String(e);
|
||||
}
|
||||
|
||||
logError_(`${message}: ${es}`);
|
||||
return `${message}: ${es}`;
|
||||
};
|
||||
|
||||
const logError_ = (message: string) => {
|
||||
log.error(`[main] [error] ${message}`);
|
||||
console.error(`[error] ${message}`);
|
||||
const logError = (message: string, e?: unknown) => {
|
||||
const m = `[error] ${messageWithError(message, e)}`;
|
||||
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[]) => {
|
||||
|
@ -97,6 +101,11 @@ export default {
|
|||
* console.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -3,6 +3,7 @@ import fs from "node:fs/promises";
|
|||
import path from "node:path";
|
||||
import { existsSync } from "original-fs";
|
||||
import type { PendingUploads, ZipItem } from "../../types/ipc";
|
||||
import log from "../log";
|
||||
import { uploadStatusStore } from "../stores/upload-status";
|
||||
|
||||
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
|
||||
// of it.
|
||||
if (allZipItems === undefined) {
|
||||
const allZipPaths = uploadStatusStore.get("filePaths") ?? [];
|
||||
const allZipPaths = uploadStatusStore.get("zipPaths") ?? [];
|
||||
const zipPaths = allZipPaths.filter((f) => existsSync(f));
|
||||
zipItems = [];
|
||||
for (const zip of zipPaths)
|
||||
zipItems = zipItems.concat(await listZipItems(zip));
|
||||
for (const zip of zipPaths) {
|
||||
try {
|
||||
zipItems = zipItems.concat(await listZipItems(zip));
|
||||
} catch (e) {
|
||||
log.error("Ignoring items in malformed zip", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
zipItems = allZipItems.filter(([z]) => existsSync(z));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue