From c31fe55b9b3fe71e6ac970529dc32edeff35ccd5 Mon Sep 17 00:00:00 2001 From: David Jakowenko Date: Mon, 16 Aug 2021 23:27:02 -0400 Subject: [PATCH 1/2] fix: better error handling when training fails to prevent stuck loading bar #71 --- api/src/util/db.util.js | 2 ++ api/src/util/train.util.js | 11 ++++++++--- frontend/src/components/Asset.vue | 2 +- frontend/src/views/Train.vue | 8 ++++++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/api/src/util/db.util.js b/api/src/util/db.util.js index 7c2dd86e..a81830bc 100644 --- a/api/src/util/db.util.js +++ b/api/src/util/db.util.js @@ -53,6 +53,8 @@ module.exports.init = async () => { )` ).run(); + db.prepare(`DELETE FROM train WHERE meta IS NULL`).run(); + await this.resync.files(); } catch (error) { console.error(`db init error: ${error.message}`); diff --git a/api/src/util/train.util.js b/api/src/util/train.util.js index 264713a9..62fa0212 100644 --- a/api/src/util/train.util.js +++ b/api/src/util/train.util.js @@ -30,7 +30,7 @@ module.exports.queue = async (files) => { name, key: `${STORAGE.PATH}/train/${name}/${filename}`, detector, - }); + }).catch((error) => ({ error: error.message })); outputs.push({ ...result }); records[i].meta = JSON.stringify(result); database.create.train(records[i]); @@ -49,9 +49,15 @@ module.exports.process = async ({ name, key, detector }) => { detector, }; } catch (error) { + if (!error.response) { + return { + message: error.message, + status: 500, + detector, + }; + } const { status, data } = error.response; const message = typeof data === 'string' ? { data } : { ...data }; - if (data.message) { console.error(`${detector} training error: ${data.message}`); } else if (data.error) { @@ -59,7 +65,6 @@ module.exports.process = async ({ name, key, detector }) => { } else { console.error(`${detector} training error: ${error.message}`); } - return { ...message, status, diff --git a/frontend/src/components/Asset.vue b/frontend/src/components/Asset.vue index 9a792186..d293d05d 100644 --- a/frontend/src/components/Asset.vue +++ b/frontend/src/components/Asset.vue @@ -73,7 +73,7 @@ :value="slotProps.data.detector" :severity=" slotProps.data.result - ? slotProps.data.result.status.toString().charAt(0) === '2' + ? slotProps?.data?.result?.status?.toString().charAt(0) === '2' ? 'success' : 'danger' : '' diff --git a/frontend/src/views/Train.vue b/frontend/src/views/Train.vue index 6cb4ee96..57f1edd0 100644 --- a/frontend/src/views/Train.vue +++ b/frontend/src/views/Train.vue @@ -130,8 +130,12 @@ export default { async files() { try { const ids = $this.matches.selected.map((obj) => obj.id); - const trained = $this.matches.selected.filter((obj) => obj.results.length); - const untrained = $this.matches.selected.filter((obj) => !obj.results.length); + const trained = $this.matches.selected.filter( + (obj) => obj.results.filter((res) => res.result.status === 200).length, + ); + const untrained = $this.matches.selected.filter( + (obj) => !obj.results.length || obj.results.filter((res) => res.result.status !== 200).length, + ); const names = [...new Set(trained.map((obj) => obj.name))]; let message = ''; if (trained.length) { From b479f3953d490d9ecc8b79ede8f3daeadd6d5bb8 Mon Sep 17 00:00:00 2001 From: David Jakowenko Date: Mon, 16 Aug 2021 23:55:57 -0400 Subject: [PATCH 2/2] build: 0.10.2 --- api/package-lock.json | 2 +- api/package.json | 2 +- frontend/package-lock.json | 2 +- frontend/package.json | 2 +- package-lock.json | 2 +- package.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/package-lock.json b/api/package-lock.json index 6c1ce348..5a195999 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -1,6 +1,6 @@ { "name": "double-take-api", - "version": "0.10.1", + "version": "0.10.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/api/package.json b/api/package.json index 1adb1962..043f7841 100644 --- a/api/package.json +++ b/api/package.json @@ -1,6 +1,6 @@ { "name": "double-take-api", - "version": "0.10.1", + "version": "0.10.2", "description": "Unified UI and API for processing and training images for facial recognition", "scripts": { "start": "node server.js", diff --git a/frontend/package-lock.json b/frontend/package-lock.json index f1a8411a..205c3409 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,6 +1,6 @@ { "name": "double-take-frontend", - "version": "0.10.1", + "version": "0.10.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/frontend/package.json b/frontend/package.json index c4b0ac46..37f2320a 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "double-take-frontend", - "version": "0.10.1", + "version": "0.10.2", "description": "Unified UI and API for processing and training images for facial recognition", "scripts": { "serve": "vue-cli-service serve", diff --git a/package-lock.json b/package-lock.json index 6887b34c..7bf0ed88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "double-take", - "version": "0.10.1", + "version": "0.10.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 09aa1f96..8c208434 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "double-take", - "version": "0.10.1", + "version": "0.10.2", "description": "Unified UI and API for processing and training images for facial recognition", "scripts": { "prepare": "husky install",