Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/io/import/processors/importSingleFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const importSingleFile: ImportHandler = async (dataSource) => {
return asLoadableResult(dataID, dataSource, 'model');
}

throw new Error('Data reader did not produce a valid dataset');
throw new Error(
`Failed to import "${dataSource.file.name}". The file may be corrupted or in an unsupported format variant.`
);
};

export default importSingleFile;
14 changes: 12 additions & 2 deletions src/io/import/processors/updateFileMimeType.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import { Skip } from '@/src/utils/evaluateChain';
import { getFileMimeType } from '@/src/io';
import { ImportHandler, asIntermediateResult } from '@/src/io/import/common';
import { MIME_TYPES } from '@/src/io/mimeTypes';

/**
* Transforms a file data source to have a mime type
* @param dataSource
*/
const updateFileMimeType: ImportHandler = async (dataSource) => {
if (dataSource.type !== 'file' || dataSource.fileType !== '') return Skip;
if (dataSource.type !== 'file') return Skip;

const knownType =
dataSource.fileType !== '' && MIME_TYPES.has(dataSource.fileType);
if (knownType) {
return Skip;
}

const mime = await getFileMimeType(dataSource.file);

if (!mime) {
throw new Error('File is unsupported');
throw new Error(
`Unrecognized file type for "${dataSource.file.name}". This file format is not supported.`
);
}

return asIntermediateResult([
Expand Down
Loading