Skip to content

Commit

Permalink
fix: better error handling when training fails to prevent stuck loadi…
Browse files Browse the repository at this point in the history
…ng bar
  • Loading branch information
jakowenko committed Aug 17, 2021
1 parent 8f760de commit 07dfd25
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions api/src/util/db.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
error.message = `db init error: ${error.message}`;
Expand Down
20 changes: 15 additions & 5 deletions api/src/util/train.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -50,12 +50,22 @@ 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 };

error.message = `${detector} training error: ${error.message}`;
console.error(error);

if (data.message) {
console.error(`${detector} training error: ${data.message}`);
} else if (data.error) {
console.error(`${detector} training error: ${data.error}`);
} else {
console.error(`${detector} training error: ${error.message}`);
}
return {
...message,
status,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Asset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
: ''
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/views/Train.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 07dfd25

Please sign in to comment.