Skip to content

Commit b7797c7

Browse files
committed
added some more error logging
1 parent 2943874 commit b7797c7

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

core/lib/pattern_assembler.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,26 +154,42 @@ var pattern_assembler = function () {
154154
//look for a json file for this template
155155
try {
156156
var jsonFilename = path.resolve(patternsPath, currentPattern.subdir, currentPattern.fileName + ".json");
157-
currentPattern.jsonFileData = fs.readJSONSync(jsonFilename);
158-
if (patternlab.config.debug) {
159-
console.log('processPatternIterative: found pattern-specific data.json for ' + currentPattern.patternPartial);
157+
try {
158+
var jsonFilenameStats = fs.statSync(jsonFilename);
159+
} catch (err) {
160+
//not a file
161+
}
162+
if (jsonFilenameStats && jsonFilenameStats.isFile()) {
163+
currentPattern.jsonFileData = fs.readJSONSync(jsonFilename);
164+
if (patternlab.config.debug) {
165+
console.log('processPatternIterative: found pattern-specific data.json for ' + currentPattern.patternPartial);
166+
}
160167
}
161168
}
162-
catch (e) {
163-
// do nothing
169+
catch (err) {
170+
console.log('There was an error parsing sibling JSON for ' + currentPattern.relPath);
171+
console.log(err);
164172
}
165173

166174
//look for a listitems.json file for this template
167175
try {
168176
var listJsonFileName = path.resolve(patternsPath, currentPattern.subdir, currentPattern.fileName + ".listitems.json");
169-
currentPattern.listitems = fs.readJSONSync(listJsonFileName);
170-
buildListItems(currentPattern);
171-
if (patternlab.config.debug) {
172-
console.log('found pattern-specific listitems.json for ' + currentPattern.patternPartial);
177+
try {
178+
var listJsonFileStats = fs.statSync(listJsonFileName);
179+
} catch (err) {
180+
//not a file
181+
}
182+
if (listJsonFileStats && listJsonFileStats.isFile()) {
183+
currentPattern.listitems = fs.readJSONSync(listJsonFileName);
184+
buildListItems(currentPattern);
185+
if (patternlab.config.debug) {
186+
console.log('found pattern-specific listitems.json for ' + currentPattern.patternPartial);
187+
}
173188
}
174189
}
175-
catch (e) {
176-
// do nothing
190+
catch (err) {
191+
console.log('There was an error parsing sibling listitem JSON for ' + currentPattern.relPath);
192+
console.log(err);
177193
}
178194

179195
//look for a markdown file for this template

core/lib/pseudopattern_hunter.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ var pseudopattern_hunter = function () {
3232
}
3333

3434
//we want to do everything we normally would here, except instead read the pseudoPattern data
35-
var variantFileData = fs.readJSONSync(path.resolve(paths.source.patterns, pseudoPatterns[i]));
36-
35+
try {
36+
var variantFileData = fs.readJSONSync(path.resolve(paths.source.patterns, pseudoPatterns[i]));
37+
} catch (err) {
38+
console.log('There was an error parsing pseudopattern JSON for ' + currentPattern.relPath);
39+
console.log(err);
40+
}
41+
3742
//extend any existing data with variant data
3843
variantFileData = plutils.mergeData(currentPattern.jsonFileData, variantFileData);
3944

0 commit comments

Comments
 (0)