diff --git a/src/formats/formats.js b/src/formats/formats.js index 2fd5e66a5c7f..6d85b045c500 100644 --- a/src/formats/formats.js +++ b/src/formats/formats.js @@ -28,7 +28,7 @@ export function formatByExtension(extension) { md: FrontmatterFormatter, markdown: FrontmatterFormatter, html: FrontmatterFormatter, - }[extension] || FrontmatterFormatter; + }[extension]; } function formatByName(name) { diff --git a/src/reducers/collections.js b/src/reducers/collections.js index 4cd50cd14323..9e0f967f86e8 100644 --- a/src/reducers/collections.js +++ b/src/reducers/collections.js @@ -4,7 +4,7 @@ import consoleError from '../lib/consoleError'; import { CONFIG_SUCCESS } from '../actions/config'; import { FILES, FOLDER } from '../constants/collectionTypes'; import { INFERABLE_FIELDS } from '../constants/fieldInference'; -import { formatToExtension, supportedFormats } from '../formats/formats'; +import { formatByExtension, formatToExtension, supportedFormats } from '../formats/formats'; const collections = (state = null, action) => { const configCollections = action.payload && action.payload.collections; @@ -32,7 +32,11 @@ function validateCollection(configCollection) { throw new Error(`Unknown collection type for collection "${ collectionName }". Collections can be either Folder based or File based.`); } if (has(configCollection, 'format') && !supportedFormats.includes(get(configCollection, 'format'))) { - throw new Error(`Unknown collection format for collection "${ collectionName }". Supported formats are ${ supportedFormats.join(',') }`); + throw new Error(`Unknown collection format for collection "${ collectionName }". Supported formats are ${ supportedFormats.join(',') }`); + } + if (!has(configCollection, 'format') && has(configCollection, 'extension') && !formatByExtension(get(configCollection, 'extension'))) { + // Cannot infer format from extension. + throw new Error(`Please set a format for collection "${ collectionName }". Supported formats are ${ supportedFormats.join(',') }`); } }