Skip to content

Commit

Permalink
Fix #4335 Handle bibtex parsing exception
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Aug 18, 2024
1 parent 35acc5b commit a53bba4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/parse/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { latexLogParser } from './parser/latexlog'
// @ts-expect-error Load unified.js from /out/src/...
import { toString } from '../../../resources/unified.js'

const logger = lw.log('Parser')

export const parser = {
bib,
log,
Expand Down Expand Up @@ -40,8 +42,14 @@ async function reset() {
return (await proxy).reset(getMacroDefs(), getEnvDefs())
}

async function bib(s: string, options?: bibtexParser.ParserOptions): Promise<bibtexParser.BibtexAst> {
return (await proxy).parseBibTeX(s, options)
async function bib(s: string, options?: bibtexParser.ParserOptions): Promise<bibtexParser.BibtexAst | undefined> {
let ast = undefined
try {
ast = (await proxy).parseBibTeX(s, options)
} catch (err) {
logger.logError('Error when parsing bib file.', err)
}
return ast
}

function stringify(ast: Ast.Ast): string {
Expand Down

0 comments on commit a53bba4

Please sign in to comment.