Skip to content

Commit

Permalink
Throw if cannot infer format from file extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
tech4him1 authored and erquhart committed Dec 6, 2017
1 parent 326dd48 commit 834c5f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/formats/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function formatByExtension(extension) {
md: FrontmatterFormatter,
markdown: FrontmatterFormatter,
html: FrontmatterFormatter,
}[extension] || FrontmatterFormatter;
}[extension];
}

function formatByName(name) {
Expand Down
8 changes: 6 additions & 2 deletions src/reducers/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(',') }`);
}
}

Expand Down

0 comments on commit 834c5f4

Please sign in to comment.