Skip to content

Commit

Permalink
Log more errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamuratak committed Oct 1, 2023
1 parent 5dedccd commit b0f21b3
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 30 deletions.
8 changes: 6 additions & 2 deletions src/components/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
6 changes: 2 additions & 4 deletions src/components/graphicspreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/components/linterlib/chktex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/components/linterlib/lacheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/components/locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
12 changes: 4 additions & 8 deletions src/components/locatorlib/synctex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/components/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b0f21b3

Please sign in to comment.