Skip to content

Commit 2676951

Browse files
committed
when reading content files, wrap every file loading with try-catch
1 parent 186a497 commit 2676951

File tree

3 files changed

+37
-42
lines changed

3 files changed

+37
-42
lines changed

package-lock.json

Lines changed: 13 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"homepage": "https://github.com/stackbithq/sourcebit-source-filesystem#readme",
2727
"dependencies": {
2828
"@stackbit/sdk": "^0.2.16",
29-
"@stackbit/utils": "^0.1.0",
29+
"@stackbit/utils": "^0.2.1",
3030
"chokidar": "^3.5.2",
3131
"fs-extra": "^10.0.0",
3232
"lodash": "^4.17.21"

src/index.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const fse = require('fs-extra');
33
const path = require('path');
44
const _ = require('lodash');
55
const { loadConfig } = require('@stackbit/sdk');
6-
const { parseFile, mapPromise, readDirRecursively } = require('@stackbit/utils');
6+
const { parseFile, mapPromise, reducePromise, readDirRecursively } = require('@stackbit/utils');
77
const { matchObjectsToModels } = require('./models-matcher');
88

99

@@ -24,6 +24,10 @@ function log(message) {
2424
console.log(`[${SOURCE}] ${message}`);
2525
}
2626

27+
function logError(message) {
28+
console.error(`[${SOURCE}] ${message}`);
29+
}
30+
2731
module.exports.bootstrap = async ({ setPluginContext, options, refresh }) => {
2832
let { watch, sources = [] } = options;
2933

@@ -137,22 +141,27 @@ async function readFiles(sources) {
137141
const ext = path.extname(filePath).substring(1);
138142
return ['yml', 'yaml', 'json', 'toml', 'md'].includes(ext);
139143
}).sort();
140-
return mapPromise(filePaths, async filePath => {
144+
return reducePromise(filePaths, async (result, filePath) => {
141145
const absFilePath = path.join(absSourcePath, filePath);
142-
const data = await parseFile(absFilePath);
143146
const relProjectPath = path.relative(absProjectPath, absFilePath);
144147
const relSourcePath = path.relative(absSourcePath, absFilePath);
145-
return _.assign({
146-
__metadata: {
147-
id: `${relProjectPath}`,
148-
source: SOURCE,
149-
sourceName: name,
150-
sourcePath: sourcePath,
151-
relSourcePath: relSourcePath,
152-
relProjectPath: relProjectPath
153-
}
154-
}, data);
155-
});
148+
try {
149+
const data = await parseFile(absFilePath);
150+
result.push(_.assign({
151+
__metadata: {
152+
id: `${relProjectPath}`,
153+
source: SOURCE,
154+
sourceName: name,
155+
sourcePath: sourcePath,
156+
relSourcePath: relSourcePath,
157+
relProjectPath: relProjectPath
158+
}
159+
}, data));
160+
} catch (error) {
161+
logError(`failed to parse file: ${relProjectPath}`);
162+
}
163+
return result;
164+
}, []);
156165
});
157166
return _.chain(result).flatten().value();
158167
}

0 commit comments

Comments
 (0)