Skip to content
Merged
30 changes: 16 additions & 14 deletions src/config/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { normalizeReceiveBetaUpdates } from "@domain/appUpdate/betaUpdates"
import { DEFAULT_COMPRESSION_LEVEL, DEFAULT_CONFIG_BASE } from "@domain/config/defaults"
import { normalizeServerBookmarks } from "@domain/servers/bookmarks"

const LOG_PREFIX = "[back] [config] [config/configManager.ts]"

const defaultConfig: ConfigType = {
...DEFAULT_CONFIG_BASE,
schemaVersion: CURRENT_CONFIG_SCHEMA,
Expand Down Expand Up @@ -90,8 +92,8 @@ export async function saveConfig(config: ConfigType): Promise<boolean> {
configReady = true
return true
} catch (err) {
logMessage("error", "[back] [config] [config/configManager.ts] [saveConfig] Error saving configuration.")
logMessage("debug", `[back] [config] [config/configManager.ts] [saveConfig] ${err}`)
logMessage("error", `${LOG_PREFIX} [saveConfig] Error saving configuration.`)
logMessage("debug", `${LOG_PREFIX} [saveConfig] ${err}`)
return false
}
}
Expand All @@ -118,8 +120,8 @@ export async function getConfig(): Promise<ConfigType> {
if (mustSave) await saveConfig(ensuredConfig)
return ensuredConfig
} catch (err) {
logMessage("error", `[back] [config] [config/configManager.ts] [getConfig] Error getting config at [PATH]. Using default config.`)
logMessage("debug", `[back] [config] [config/configManager.ts] [getConfig] Error getting config at [PATH]: ${err}`)
logMessage("error", `${LOG_PREFIX} [getConfig] Error getting config at [PATH]. Using default config.`)
logMessage("debug", `${LOG_PREFIX} [getConfig] Error getting config at [PATH]: ${err}`)
await saveConfig(defaultConfig)
return defaultConfig
}
Expand All @@ -130,22 +132,22 @@ export async function ensureConfig(): Promise<boolean> {
configPath = join(app.getPath("userData"), "config.json")
try {
if (!(await fse.pathExists(configPath))) {
logMessage("info", `[back] [config] [config/configManager.ts] [ensureConfig] Config not found. Creating default config.`)
logMessage("info", `${LOG_PREFIX} [ensureConfig] Config not found. Creating default config.`)
return await saveConfig(defaultConfig)
}
configReady = true
logMessage("info", `[back] [config] [config/configManager.ts] [ensureConfig] Config found at [PATH].`)
logMessage("info", `${LOG_PREFIX} [ensureConfig] Config found at [PATH].`)
return true
} catch (err) {
logMessage("error", `[back] [config] [config/configManager.ts] [ensureConfig] Error ensuring config.`)
logMessage("error", `[back] [config] [config/configManager.ts] [ensureConfig] Error ensuring config at [PATH]: ${err}`)
logMessage("error", `${LOG_PREFIX} [ensureConfig] Error ensuring config.`)
logMessage("error", `${LOG_PREFIX} [ensureConfig] Error ensuring config at [PATH]: ${err}`)
return false
}
}

/** Says what the schema pipeline did with the stored document, and at what level it deserves saying. */
function logConfigMigration(migration: ReturnType<typeof migrateConfigDocument>): void {
const prefix = "[back] [config] [config/configManager.ts] [getConfig]"
const prefix = `${LOG_PREFIX} [getConfig]`
const steps = migration.applied.map((step) => `${step.fromSchema}->${step.toSchema}`).join(", ")

switch (migration.outcome) {
Expand Down Expand Up @@ -189,10 +191,10 @@ async function migrateLegacyAccount(config: unknown): Promise<boolean> {
try {
await saveAccountSecrets(legacyAccount.publicAccount.playerUid, legacyAccount.secrets)
} catch {
logMessage("warn", "[back] [config] [configManager.ts] Legacy account credentials were not migrated to secure storage.")
logMessage("warn", `${LOG_PREFIX} Legacy account credentials were not migrated to secure storage.`)
}
} else {
logMessage("warn", "[back] [config] [configManager.ts] Legacy account credentials were invalid and were discarded.")
logMessage("warn", `${LOG_PREFIX} Legacy account credentials were invalid and were discarded.`)
}

return true
Expand Down Expand Up @@ -235,7 +237,7 @@ async function migrateAccountStore(legacyDocument: unknown, config: ConfigType):
try {
return await adoptLegacySingleAccountSecrets(uid)
} catch {
logMessage("warn", "[back] [config] [configManager.ts] The stored account session was not carried into the multi-account store. Retrying on the next launch.")
logMessage("warn", `${LOG_PREFIX} The stored account session was not carried into the multi-account store. Retrying on the next launch.`)
return false
}
}
Expand Down Expand Up @@ -299,8 +301,8 @@ async function reconcileConfigBackup(migrationRan: boolean): Promise<void> {
stripLegacyAccountSecrets(document)
await writeJsonAtomic(backupPath, document, { mode: 0o600, spaces: 2 })
} catch (err) {
logMessage("warn", "[back] [config] [configManager.ts] Could not reconcile the pre-migration config backup.")
logMessage("debug", `[back] [config] [configManager.ts] ${err}`)
logMessage("warn", `${LOG_PREFIX} Could not reconcile the pre-migration config backup.`)
logMessage("debug", `${LOG_PREFIX} ${err}`)
}
}

Expand Down
22 changes: 12 additions & 10 deletions src/ipc/adapters/modScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { sweepCacheFolder } from "@src/ipc/cacheSweep"
import { assertSafeFileName } from "@src/ipc/validation"
import { logMessage } from "@src/utils/logManager"

const LOG_PREFIX = "[back] [mods] [ipc/adapters/modScan.ts]"

/** Entry inside a mod archive carrying its metadata. */
const MODINFO_ENTRY = "modinfo.json"

Expand Down Expand Up @@ -45,7 +47,7 @@ function readModArchive(archivePath: string): Promise<ModArchiveResult> {
return new Promise<ModArchiveResult>((resolve) => {
yauzl.open(archivePath, { lazyEntries: true }, (openErr, zip) => {
if (openErr || !zip) {
logMessage("debug", `[back] [mods] [ipc/adapters/modScan.ts] [readModArchive] Could not open a mod archive.`)
logMessage("debug", `${LOG_PREFIX} [readModArchive] Could not open a mod archive.`)
return resolve({ ok: false, problem: "unreadable-archive" })
}

Expand Down Expand Up @@ -79,7 +81,7 @@ function readModArchive(archivePath: string): Promise<ModArchiveResult> {
const collect = (entry: yauzl.Entry, limit: number, onDone: (bytes: Buffer) => void, onOversize: () => void, onUnreadable: () => void): void => {
zip.openReadStream(entry, (streamErr, stream) => {
if (streamErr || !stream) {
logMessage("debug", `[back] [mods] [ipc/adapters/modScan.ts] [readModArchive] Could not read a mod archive entry.`)
logMessage("debug", `${LOG_PREFIX} [readModArchive] Could not read a mod archive entry.`)
return onUnreadable()
}

Expand All @@ -97,7 +99,7 @@ function readModArchive(archivePath: string): Promise<ModArchiveResult> {
})
stream.on("end", () => onDone(Buffer.concat(chunks)))
stream.on("error", () => {
logMessage("debug", `[back] [mods] [ipc/adapters/modScan.ts] [readModArchive] Error reading a mod archive entry.`)
logMessage("debug", `${LOG_PREFIX} [readModArchive] Error reading a mod archive entry.`)
onUnreadable()
})
})
Expand Down Expand Up @@ -146,7 +148,7 @@ function readModArchive(archivePath: string): Promise<ModArchiveResult> {

zip.on("end", () => settle({ ok: true, content }))
zip.on("error", () => {
logMessage("debug", `[back] [mods] [ipc/adapters/modScan.ts] [readModArchive] Error walking a mod archive.`)
logMessage("debug", `${LOG_PREFIX} [readModArchive] Error walking a mod archive.`)
settle({ ok: false, problem: "unreadable-archive" })
})

Expand Down Expand Up @@ -194,8 +196,8 @@ export function createIconStorePort(): IconStore {
}
return imageName
} catch (err) {
logMessage("error", `[back] [mods] [ipc/adapters/modScan.ts] [createIconStorePort] Error saving a mod's icon.`)
logMessage("debug", `[back] [mods] [ipc/adapters/modScan.ts] [createIconStorePort] Error saving a mod's icon: ${err}`)
logMessage("error", `${LOG_PREFIX} [createIconStorePort] Error saving a mod's icon.`)
logMessage("debug", `${LOG_PREFIX} [createIconStorePort] Error saving a mod's icon: ${err}`)
return undefined
}
}
Expand Down Expand Up @@ -265,8 +267,8 @@ export function createModImageStorePort(): ModImageCache {
await writeFileAtomic(target, bytes)
return name
} catch (err) {
logMessage("error", `[back] [mods] [ipc/adapters/modScan.ts] [createModImageStorePort] Error saving a ModDB logo.`)
logMessage("debug", `[back] [mods] [ipc/adapters/modScan.ts] [createModImageStorePort] Error saving a ModDB logo: ${err}`)
logMessage("error", `${LOG_PREFIX} [createModImageStorePort] Error saving a ModDB logo.`)
logMessage("debug", `${LOG_PREFIX} [createModImageStorePort] Error saving a ModDB logo: ${err}`)
return undefined
}
}
Expand Down Expand Up @@ -319,7 +321,7 @@ export async function pruneModIconCache(maxBytes: number = MOD_ICON_CACHE_MAX_BY
async function doPruneModIconCache(maxBytes: number): Promise<void> {
await sweepCacheFolder({
folder: modImagesFolder(),
origin: "[back] [mods] [ipc/adapters/modScan.ts] [pruneModIconCache]",
origin: `${LOG_PREFIX} [pruneModIconCache]`,
subject: "the icon cache",
accepts: (name) => {
// Throws its own reason rather than returning false, and the sweep logs it.
Expand Down Expand Up @@ -363,7 +365,7 @@ export function createModsDirectoryReaderPort(): DirectoryReader {
try {
assertSafeFileName(entry)
if ((await fse.lstat(join(path, entry))).isSymbolicLink()) {
logMessage("debug", `[back] [mods] [ipc/adapters/modScan.ts] [listFileNames] Skipping a symbolic link inside the Mods folder.`)
logMessage("debug", `${LOG_PREFIX} [listFileNames] Skipping a symbolic link inside the Mods folder.`)
continue
}
names.push(entry)
Expand Down
19 changes: 10 additions & 9 deletions src/ipc/handlers/accountHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { AccountStoreUnreadableError, removeAccountSecrets, saveAccountSecrets }
import type { AccountSaveOutcome } from "@src/ipc/accountStore"
import { getErrorMessage, logMessage } from "@src/utils/logManager"

const LOG_PREFIX = "[back] [ipc] [ipc/handlers/accountHandlers.ts]"

const LOGIN_URL = new URL("https://auth3.vintagestory.at/v2/gamelogin")

/**
Expand Down Expand Up @@ -71,19 +73,18 @@ async function settle(verdict: LoginVerdict): Promise<AccountLoginResult> {
// socket: `ENOSPC` from a keyring write and `ENOSPC` from a socket look identical
// by then, and this call site is the only one that knows which it was.
if (!(error instanceof AccountStoreUnreadableError)) throw new AccountStorageFailure(error)
logMessage("error", "[back] [ipc] [accountHandlers.ts] [LOGIN] The account store is unreadable and could not be copied aside, so it was left untouched. The session was not saved.")
logMessage("debug", `[back] [ipc] [accountHandlers.ts] [LOGIN] ${getErrorMessage(error)}`)
logMessage("error", `${LOG_PREFIX} [LOGIN] The account store is unreadable and could not be copied aside, so it was left untouched. The session was not saved.`)
logMessage("debug", `${LOG_PREFIX} [LOGIN] ${getErrorMessage(error)}`)
return sessionStoreUnreadableResult()
}

if (outcome === "saved-after-rebuild")
logMessage("warn", "[back] [ipc] [accountHandlers.ts] [LOGIN] The account store could not be read; it was copied aside and rebuilt around this login. Other saved accounts must log in again.")
logMessage("warn", `${LOG_PREFIX} [LOGIN] The account store could not be read; it was copied aside and rebuilt around this login. Other saved accounts must log in again.`)

// No keyring on this machine, so nothing was written and the session lives in this process
// only (#481). The login itself stands: the service accepted these credentials, and refusing
// to report that left the player unable to play at all over a missing wallet.
if (outcome === "saved-in-memory")
logMessage("warn", "[back] [ipc] [accountHandlers.ts] [LOGIN] No system keyring is available, so this session is held in memory for this run and was not written to disk.")
if (outcome === "saved-in-memory") logMessage("warn", `${LOG_PREFIX} [LOGIN] No system keyring is available, so this session is held in memory for this run and was not written to disk.`)

return {
status: "success",
Expand All @@ -100,11 +101,11 @@ async function settle(verdict: LoginVerdict): Promise<AccountLoginResult> {
// The toast collapses every refusal into "invalid email or password"; the
// service's own reason string is the only way to tell a real credential
// mismatch from anything else it may refuse for. Server enum, never user data.
logMessage("debug", `[back] [ipc] [accountHandlers.ts] [LOGIN] Service refused the login, reason: "${verdict.serverReason}".`)
logMessage("debug", `${LOG_PREFIX} [LOGIN] Service refused the login, reason: "${verdict.serverReason}".`)
return badCredentialsResult()
case "unreadable-response": {
const outcome = unexpectedResponseOutcome(verdict)
logMessage("error", `[back] [ipc] [accountHandlers.ts] [LOGIN] ${outcome.logMessage}`)
logMessage("error", `${LOG_PREFIX} [LOGIN] ${outcome.logMessage}`)
return outcome.result
}
}
Expand Down Expand Up @@ -140,8 +141,8 @@ ipcMain.handle(IPC_CHANNELS.ACCOUNT_MANAGER.LOGIN, async (event, email: unknown,
// instead, which still tells a network failure from an HTTP status from a
// keyring that is not there from a disk with no room left on it.
const reason = loginFailureReason(error)
logMessage("error", "[back] [ipc] [accountHandlers.ts] [LOGIN] Login failed.")
logMessage("debug", `[back] [ipc] [accountHandlers.ts] [LOGIN] Login failure reason: ${reason}.`)
logMessage("error", `${LOG_PREFIX} [LOGIN] Login failed.`)
logMessage("debug", `${LOG_PREFIX} [LOGIN] Login failure reason: ${reason}.`)

// A reason `loginFailureFamily` can place resolves instead of throwing, so the
// renderer can say which of DNS/refused/timeout, a certificate, an HTTP error the
Expand Down
Loading
Loading