Merge pull request #52 from boazpoolman/fix/warning-for-missing-data

Gracefully warn about corrupt data
pull/58/head
Boaz Poolman 2022-04-25 14:30:03 +02:00 committed by GitHub
commit 2adc044c9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -183,6 +183,12 @@ const ConfigType = class ConfigType {
await Promise.all(Object.values(AllConfig).map(async (config) => {
const combinedUid = getCombinedUid(this.uidKeys, config);
const combinedUidWhereFilter = getCombinedUidWhereFilter(this.uidKeys, config);
if (!combinedUid) {
strapi.log.warn(logMessage(`Missing data for entity with id ${config.id} of type ${this.configPrefix}`));
return;
}
// Check if the config should be excluded.
const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => `${this.configPrefix}.${combinedUid}`.startsWith(option)));
if (shouldExclude) return;

View File

@ -4,6 +4,7 @@ const { isEmpty } = require('lodash');
const fs = require('fs');
const util = require('util');
const difference = require('../utils/getObjectDiff');
const { logMessage } = require('../utils');
/**
* Main services for config import/export.
@ -118,6 +119,12 @@ module.exports = () => ({
}
const fileContents = await strapi.plugin('config-sync').service('main').readConfigFile(type, name);
if (!fileContents) {
strapi.log.warn(logMessage(`An empty config file '${file}' was found in the sync directory`));
return;
}
fileConfigs[`${type}.${formattedName}`] = fileContents;
}));