diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-07-11 23:23:33 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-07-11 23:23:33 +0300 |
| commit | 0f73cb78ec636b6c505a93ddd8acb71a1b30a8ae (patch) | |
| tree | e2ddd51ae1aef63b87ae4a07da2e7c5d274b0de5 | |
| parent | 7ea1eb2ffcec40dcb2fcdc737ccfab4c5779b034 (diff) | |
Fix error handling
| -rw-r--r-- | build.js | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -28,20 +28,19 @@ fs.cpSync(SRC_DIR, DIST_DIR, { recursive: true }); const htmlTemplate = fs.readFileSync(HTML_TEMP_PATH, "utf-8");
-const galleryJsonList = fs.readdirSync(GALLERY_DIR);
+let galleryJsonList = [];
+try {
+ galleryJsonList = fs.readdirSync(GALLERY_DIR);
+} catch (err) {
+ if (err.message?.includes("ENOENT")) {
+ console.warn("Could not read galleries, using empty list.");
+ } else {
+ throw err;
+ }
+}
+
const galleryViews = galleryJsonList
- .map((fileName) => {
- try {
- return fs.readFileSync(path.join(GALLERY_DIR, fileName), "utf-8");
- } catch (err) {
- if (err.message?.includes("ENOENT")) {
- console.warn("Could not read galleries, using empty list");
- return []
- } else {
- throw err;
- }
- }
- })
+ .map((fileName) => fs.readFileSync(path.join(GALLERY_DIR, fileName), "utf-8"))
.map(JSON.parse)
.map((gallery) => {
const rows = sliceIntoChunks(gallery["images"], gallery["column_count"]);
@@ -54,3 +53,5 @@ const galleryViews = galleryJsonList const renderedHtml = M.render(htmlTemplate, { galleries: galleryViews} );
fs.writeFileSync(HTML_OUT_PATH, renderedHtml);
+
+console.log("Done.");
\ No newline at end of file |
