Skip to content

Commit 1703471

Browse files
committed
Wrap in try catch
1 parent ea67cfa commit 1703471

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

javascript/index.js

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { DOMParser as dom } from "xmldom";
88
const readdir = util.promisify(fs.readdir);
99
const open = util.promisify(fs.open);
1010
const readFile = util.promisify(fs.readFile);
11+
const errors = [];
1112

1213
// latex (pdf version)
1314
import {
@@ -157,31 +158,35 @@ async function translateXml(filepath, filename, option) {
157158
}
158159

159160
if (parseType == "json") {
160-
const relativeFilePath = path.join(
161-
filepath,
162-
filename.replace(/\.xml$/, "") + ".html"
163-
);
164-
165-
if (option == "generateTOC") {
166-
generateTOC(doc, tableOfContent, relativeFilePath);
167-
return;
168-
} else if (option == "setupSnippet") {
169-
setupSnippetsJson(doc.documentElement);
170-
setupReferencesJson(doc.documentElement, relativeFilePath);
171-
return;
172-
} else if (option == "parseXml") {
173-
const jsonObj = [];
174-
parseXmlJson(doc, jsonObj, relativeFilePath);
175-
176-
const outputFile = path.join(
177-
outputDir,
178-
tableOfContent[relativeFilePath].index + ".json"
161+
try {
162+
const relativeFilePath = path.join(
163+
filepath,
164+
filename.replace(/\.xml$/, "") + ".html"
179165
);
180-
const stream = fs.createWriteStream(outputFile);
181-
stream.once("open", fd => {
182-
stream.write(JSON.stringify(jsonObj));
183-
stream.end();
184-
});
166+
167+
if (option == "generateTOC") {
168+
generateTOC(doc, tableOfContent, relativeFilePath);
169+
return;
170+
} else if (option == "setupSnippet") {
171+
setupSnippetsJson(doc.documentElement);
172+
setupReferencesJson(doc.documentElement, relativeFilePath);
173+
return;
174+
} else if (option == "parseXml") {
175+
const jsonObj = [];
176+
parseXmlJson(doc, jsonObj, relativeFilePath);
177+
178+
const outputFile = path.join(
179+
outputDir,
180+
tableOfContent[relativeFilePath].index + ".json"
181+
);
182+
const stream = fs.createWriteStream(outputFile);
183+
stream.once("open", fd => {
184+
stream.write(JSON.stringify(jsonObj));
185+
stream.end();
186+
});
187+
}
188+
} catch (error) {
189+
errors.push(path.join(filepath, filename) + " " + error);
185190
}
186191
return;
187192
}

0 commit comments

Comments
 (0)