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: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"express": "^4.17.1",
"fs-extra": "^9.0.1",
"git-describe": "^4.0.4",
"jest": "^26.0.1",
"jest": "^26.6.3",
"jest-transform-stub": "^2.0.0",
"mime-types": "^2.1.27",
"mock-fs": "^4.13.0",
Expand All @@ -115,7 +115,7 @@
"rollup-plugin-vue": "^5.1.9",
"sass": "^1.26.3",
"sass-loader": "^8.0.2",
"ts-jest": "^26.0.0",
"ts-jest": "^26.5.2",
"tsc-alias": "^1.2.0",
"typescript": "~3.8.3",
"vue-cli-plugin-electron-builder": "^2.0.0-beta.5",
Expand Down
10 changes: 10 additions & 0 deletions client/platform/desktop/backend/native/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ mockfs({
'otherfile.txt': '',
nomime: '',
},
annotationEmptySuccess: {
'video1.mp4': '',
'result_foo.json': '',
},
annotationFail: {
'video1.mp4': '',
'file1.csv': '',
Expand Down Expand Up @@ -319,6 +323,12 @@ describe('native.common', () => {
expect(meta.originalBasePath).toBe('/home/user/data/videoSuccess');
});

it('importMedia empty json file success', async () => {
const meta = await common.importMedia(settings, '/home/user/data/annotationEmptySuccess/video1.mp4', updater, { checkMedia, convertMedia });
const tracks = await common.loadDetections(settings, meta.id);
expect(tracks).toEqual({});
});

it('importMedia various failure modes', async () => {
await expect(common.importMedia(settings, '/fake/path', updater, { checkMedia, convertMedia }))
.rejects.toThrow('file or directory not found');
Expand Down
17 changes: 15 additions & 2 deletions client/platform/desktop/backend/native/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ async function getValidatedProjectDir(settings: Settings, datasetId: string) {
*/
async function loadJsonMetadata(metaAbsPath: string): Promise<JsonMeta> {
const rawBuffer = await fs.readFile(metaAbsPath, 'utf-8');
const metaJson = JSON.parse(rawBuffer);
let metaJson;
try {
metaJson = JSON.parse(rawBuffer);
} catch (err) {
throw new Error(`Unable to parse ${metaAbsPath}: ${err}`);
}
/* check if this file meets the current schema version */
if ('version' in metaJson) {
const { version } = metaJson;
Expand All @@ -127,7 +132,15 @@ async function loadJsonMetadata(metaAbsPath: string): Promise<JsonMeta> {
*/
async function loadJsonTracks(tracksAbsPath: string): Promise<MultiTrackRecord> {
const rawBuffer = await fs.readFile(tracksAbsPath, 'utf-8');
const annotationData = JSON.parse(rawBuffer) as MultiTrackRecord;
if (rawBuffer.length === 0) {
return {}; // Return empty object if file was empty
}
let annotationData: MultiTrackRecord = {};
try {
annotationData = JSON.parse(rawBuffer) as MultiTrackRecord;
} catch (err) {
throw new Error(`Unable to parse ${tracksAbsPath}: ${err}`);
}
// TODO: somehow verify the schema of this file
if (Array.isArray(annotationData)) {
throw new Error('object expected in track json');
Expand Down
Loading