Skip to content

Commit 2adc044

Browse files
authored
Merge pull request #52 from boazpoolman/fix/warning-for-missing-data
Gracefully warn about corrupt data
2 parents 47f8438 + a44db27 commit 2adc044

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

server/config/type.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ const ConfigType = class ConfigType {
183183
await Promise.all(Object.values(AllConfig).map(async (config) => {
184184
const combinedUid = getCombinedUid(this.uidKeys, config);
185185
const combinedUidWhereFilter = getCombinedUidWhereFilter(this.uidKeys, config);
186+
187+
if (!combinedUid) {
188+
strapi.log.warn(logMessage(`Missing data for entity with id ${config.id} of type ${this.configPrefix}`));
189+
return;
190+
}
191+
186192
// Check if the config should be excluded.
187193
const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => `${this.configPrefix}.${combinedUid}`.startsWith(option)));
188194
if (shouldExclude) return;

server/services/main.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { isEmpty } = require('lodash');
44
const fs = require('fs');
55
const util = require('util');
66
const difference = require('../utils/getObjectDiff');
7+
const { logMessage } = require('../utils');
78

89
/**
910
* Main services for config import/export.
@@ -118,6 +119,12 @@ module.exports = () => ({
118119
}
119120

120121
const fileContents = await strapi.plugin('config-sync').service('main').readConfigFile(type, name);
122+
123+
if (!fileContents) {
124+
strapi.log.warn(logMessage(`An empty config file '${file}' was found in the sync directory`));
125+
return;
126+
}
127+
121128
fileConfigs[`${type}.${formattedName}`] = fileContents;
122129
}));
123130

0 commit comments

Comments
 (0)