From b0f21b3a8454c0485f998cfe5da92ad7b4439294 Mon Sep 17 00:00:00 2001 From: Takashi Tamura Date: Mon, 2 Oct 2023 08:26:15 +0900 Subject: [PATCH] Log more errors. --- src/components/builder.ts | 8 ++++++-- src/components/graphicspreview.ts | 6 ++---- src/components/linterlib/chktex.ts | 10 +++++----- src/components/linterlib/lacheck.ts | 10 +++++----- src/components/locator.ts | 6 ++---- src/components/locatorlib/synctex.ts | 12 ++++-------- src/components/manager.ts | 4 +++- src/components/viewer.ts | 2 +- 8 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/components/builder.ts b/src/components/builder.ts index 4ca8bdde..9a4a655c 100644 --- a/src/components/builder.ts +++ b/src/components/builder.ts @@ -61,10 +61,14 @@ export class Builder { cp.execSync(`taskkill /F /T /PID ${pid}`, { timeout: 1000 }) } } catch (e) { - this.extension.logger.error(`Error when killing child processes of the current process. ${inspectReadable(e)}`) + this.extension.logger.error(`Error when killing child processes of the current process: ${inspectReadable(e)}`) } finally { - proc.kill() this.extension.logger.info(`Kill the current process. PID: ${pid}`) + try { + proc.kill() + } catch (e) { + this.extension.logger.error(`Error when killing the current process: ${inspectReadable(e)}`) + } } } else { this.extension.logger.info('LaTeX build process to kill is not found.') diff --git a/src/components/graphicspreview.ts b/src/components/graphicspreview.ts index 09f76f8e..2c72ad2c 100644 --- a/src/components/graphicspreview.ts +++ b/src/components/graphicspreview.ts @@ -102,11 +102,9 @@ export class GraphicsPreview { return undefined } return dataUrl - } catch (e: unknown) { + } catch (e) { this.extension.logger.error(`Failed to renderGraphicsAsDataUrl: ${pdfFilePath}`) - if (e instanceof Error) { - this.extension.logger.logError(e) - } + this.extension.logger.logError(e) return undefined } } diff --git a/src/components/linterlib/chktex.ts b/src/components/linterlib/chktex.ts index 63522e7e..403c039c 100644 --- a/src/components/linterlib/chktex.ts +++ b/src/components/linterlib/chktex.ts @@ -8,6 +8,7 @@ import { convertFilenameEncoding } from '../../utils/convertfilename' import { existsPath, readFilePath } from '../../lib/lwfs/lwfs' import type { Logger } from '../logger' import type { Manager } from '../manager' +import { inspectReadable } from '../../utils/inspect' interface ChkTeXLogEntry { @@ -67,14 +68,13 @@ export class ChkTeX implements ILinter { } } - let stdout: string + let stdout: string | undefined try { stdout = await this.#linterUtil.processWrapper(linterid, command, args.concat(requiredArgs).filter(arg => arg !== ''), {cwd: path.dirname(filePath)}, content) - } catch (err: any) { - if ('stdout' in err) { + } catch (err) { + this.extension.logger.error(`chktex failed: ${inspectReadable({command, args, err})}`) + if (err instanceof Object && 'stdout' in err) { stdout = err.stdout as string - } else { - return undefined } } diff --git a/src/components/linterlib/lacheck.ts b/src/components/linterlib/lacheck.ts index ead4794d..2fd5c693 100644 --- a/src/components/linterlib/lacheck.ts +++ b/src/components/linterlib/lacheck.ts @@ -7,6 +7,7 @@ import { convertFilenameEncoding } from '../../utils/convertfilename' import { existsPath } from '../../lib/lwfs/lwfs' import type { Logger } from '../logger' import type { Manager } from '../manager' +import { inspectReadable } from '../../utils/inspect' interface LaCheckLogEntry { @@ -47,14 +48,13 @@ export class LaCheck implements ILinter { const configuration = vscode.workspace.getConfiguration('latex-toybox', configScope) const command = configuration.get('linting.lacheck.exec.path') as string - let stdout: string + let stdout: string | undefined try { stdout = await this.#linterUtil.processWrapper(linterid, command, [filePath], {cwd: path.dirname(filePath)}, content) - } catch (err: any) { - if ('stdout' in err) { + } catch (err) { + this.extension.logger.error(`lacheck failed: ${inspectReadable({command, filePath, err})}`) + if (err instanceof Object && 'stdout' in err) { stdout = err.stdout as string - } else { - return undefined } } diff --git a/src/components/locator.ts b/src/components/locator.ts index 68ceef15..9ef47853 100644 --- a/src/components/locator.ts +++ b/src/components/locator.ts @@ -323,10 +323,8 @@ export class Locator { editor.selection = new vscode.Selection(pos, pos) await vscode.commands.executeCommand('revealLine', {lineNumber: row, at: 'center'}) this.animateToNotify(editor, pos) - } catch (e: unknown) { - if (e instanceof Error) { - this.extension.logger.logError(e) - } + } catch (e) { + this.extension.logger.logError(e) } } diff --git a/src/components/locatorlib/synctex.ts b/src/components/locatorlib/synctex.ts index fd72fab4..5eeb66f7 100644 --- a/src/components/locatorlib/synctex.ts +++ b/src/components/locatorlib/synctex.ts @@ -87,12 +87,10 @@ export class SyncTexJs { try { const s = (await readFileAsBuffer(vscode.Uri.file(synctexFile))).toString('binary') return parseSyncTex(s) - } catch (e: unknown) { + } catch (e) { if (await existsPath(synctexFile)) { this.extension.logger.error(`[SyncTexJs] parseSyncTex failed with: ${synctexFile}`) - if (e instanceof Error) { - this.extension.logger.logError(e) - } + this.extension.logger.logError(e) } } @@ -101,12 +99,10 @@ export class SyncTexJs { const b = zlib.gunzipSync(data) const s = b.toString('binary') return parseSyncTex(s) - } catch (e: unknown) { + } catch (e) { if (await existsPath(synctexFileGz)) { this.extension.logger.error(`[SyncTexJs] parseSyncTex failed with: ${synctexFileGz}`) - if (e instanceof Error) { - this.extension.logger.logError(e) - } + this.extension.logger.logError(e) } } diff --git a/src/components/manager.ts b/src/components/manager.ts index 27eda950..1506f0ae 100644 --- a/src/components/manager.ts +++ b/src/components/manager.ts @@ -524,7 +524,9 @@ export class Manager { this.extension.logger.info(`Found files that might be root, choose the first one: ${candidates}`) return candidates[0] } - } catch (e) {} + } catch (e) { + this.extension.logger.error(`Error when calling findRootInWorkspace(): ${inspectReadable(e)}`) + } return undefined } diff --git a/src/components/viewer.ts b/src/components/viewer.ts index 7b32b315..74a18265 100644 --- a/src/components/viewer.ts +++ b/src/components/viewer.ts @@ -150,7 +150,7 @@ export class Viewer { this.extension.logger.info(`Serving PDF file at ${url}`) await vscode.env.openExternal(vscode.Uri.parse(url, true)) this.extension.logger.info(`Open PDF viewer for ${pdfFileUri.toString(true)}`) - } catch (e: unknown) { + } catch (e) { void vscode.window.showInputBox({ prompt: 'Unable to open browser. Please copy and visit this link.', value: url