Skip to content

Commit

Permalink
Don't throw raw strings but always Error objects
Browse files Browse the repository at this point in the history
  • Loading branch information
peace-maker committed Dec 23, 2024
1 parent b95b5b2 commit fd7e655
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 84 deletions.
2 changes: 1 addition & 1 deletion web/src/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ const APIClient = {
if (guard(response.data)) {
return response.data;
}
throw "Unexpected response, types mismatch";
throw new Error("Unexpected response, types mismatch");
},
};

Expand Down
10 changes: 5 additions & 5 deletions web/src/components/CTFWizardDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ function createService() {
service_by_port_loading.value = false;
EventBus.emit("showMessage", `Service ${serviceName.value} created.`);
})
.catch((err: string) => {
.catch((err: Error) => {
service_by_port_error.value = true;
service_by_port_loading.value = false;
EventBus.emit("showError", err);
EventBus.emit("showError", err.message);
});
}
Expand All @@ -192,15 +192,15 @@ function createFlagTags() {
.then((res) => {
const rejected = res.filter((r) => r.status === "rejected");
if (rejected.length != 0) {
throw rejected.map((r) => r.reason as string).join("; ");
throw new Error(rejected.map((r) => r.reason as string).join("; "));
}
visible.value = false;
flag_regex_loading.value = false;
})
.catch((err: string) => {
.catch((err: Error) => {
flag_regex_error.value = true;
flag_regex_loading.value = false;
EventBus.emit("showError", err);
EventBus.emit("showError", err.message);
});
}
</script>
4 changes: 2 additions & 2 deletions web/src/components/ConverterResetDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ function resetConverterAction() {
.then(() => {
visible.value = false;
})
.catch((err: string) => {
.catch((err: Error) => {
error.value = true;
loading.value = false;
EventBus.emit("showError", err);
EventBus.emit("showError", err.message);
});
}
</script>
12 changes: 6 additions & 6 deletions web/src/components/Converters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ onMounted(() => {
});
function refreshConverters() {
store.updateTags().catch((err: string) => {
EventBus.emit("showError", `Failed to update tags: ${err}`);
store.updateTags().catch((err: Error) => {
EventBus.emit("showError", `Failed to update tags: ${err.message}`);
});
store.updateConverters().catch((err: string) => {
EventBus.emit("showError", `Failed to update converters: ${err}`);
store.updateConverters().catch((err: Error) => {
EventBus.emit("showError", `Failed to update converters: ${err.message}`);
});
}
Expand All @@ -170,8 +170,8 @@ function showErrorLog(process: ProcessStats, converter: ConverterStatistics) {
fetchStderrError.value = "Stderr is empty";
}
})
.catch((err: string | Error) => {
fetchStderrError.value = err.toString();
.catch((err: Error) => {
fetchStderrError.value = err.message;
})
.finally(() => {
loadingStderr.value = false;
Expand Down
8 changes: 4 additions & 4 deletions web/src/components/Graph.vue
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,8 @@ graphStore.$subscribe((_mutation, state) => {
theme: colorscheme,
},
} as ApexCharts.ApexOptions)
.catch((err: string) => {
EventBus.emit("showError", `Failed to update graph: ${err}`);
.catch((err: Error) => {
EventBus.emit("showError", `Failed to update graph: ${err.message}`);
});
});
chartData.value = [];
Expand Down Expand Up @@ -716,8 +716,8 @@ function fetchGraphLocal() {
query as string,
type as GraphType,
)
.catch((err: string) => {
EventBus.emit("showError", `Failed to update graph: ${err}`);
.catch((err: Error) => {
EventBus.emit("showError", `Failed to update graph: ${err.message}`);
});
}
</script>
Expand Down
8 changes: 4 additions & 4 deletions web/src/components/Navigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ onMounted(() => {
.then(() => {
if (store.tags?.length === 0) EventBus.emit("showCTFWizard");
})
.catch((err: string) => {
EventBus.emit("showError", `Failed to update tags: ${err}`);
.catch((err: Error) => {
EventBus.emit("showError", `Failed to update tags: ${err.message}`);
});
store.updateStatus().catch((err: string) => {
EventBus.emit("showError", `Failed to update status: ${err}`);
store.updateStatus().catch((err: Error) => {
EventBus.emit("showError", `Failed to update status: ${err.message}`);
});
});
Expand Down
15 changes: 9 additions & 6 deletions web/src/components/PcapOverIP.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ onMounted(() => {
});
function refresh() {
store.updatePcapOverIPEndpoints().catch((err: string) => {
store.updatePcapOverIPEndpoints().catch((err: Error) => {
EventBus.emit(
"showError",
`Failed to update PCAP-over-IP endpoints: ${err}`,
`Failed to update PCAP-over-IP endpoints: ${err.message}`,
);
});
}
Expand All @@ -224,10 +224,13 @@ function add() {
newAddress.value = "";
refresh();
})
.catch((err: string) => {
.catch((err: Error) => {
addDialogLoading.value = false;
addDialogError.value = true;
EventBus.emit("showError", `Failed to add PCAP-over-IP endpoint: ${err}`);
EventBus.emit(
"showError",
`Failed to add PCAP-over-IP endpoint: ${err.message}`,
);
});
}
function del() {
Expand All @@ -240,10 +243,10 @@ function del() {
delDialogLoading.value = false;
refresh();
})
.catch((err: string) => {
.catch((err: Error) => {
EventBus.emit(
"showError",
`Failed to delete PCAP-over-IP endpoint: ${err}`,
`Failed to delete PCAP-over-IP endpoint: ${err.message}`,
);
delDialogError.value = true;
delDialogLoading.value = false;
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/Pcaps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ const headers = [
];
onMounted(() => {
store.updatePcaps().catch((err: string) => {
EventBus.emit("showError", `Failed to update pcaps: ${err}`);
store.updatePcaps().catch((err: Error) => {
EventBus.emit("showError", `Failed to update pcaps: ${err.message}`);
});
});
</script>
Expand Down
18 changes: 12 additions & 6 deletions web/src/components/Results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ function fetchStreams(forceUpdate = false) {
return;
}
streams.searchStreams(query, page).catch((err: string) => {
EventBus.emit("showError", `Failed to fetch streams: ${err}`);
streams.searchStreams(query, page).catch((err: Error) => {
EventBus.emit("showError", `Failed to fetch streams: ${err.message}`);
});
selected.value = [];
}
Expand All @@ -441,12 +441,18 @@ function markSelectedStreams(tagId: string, value: boolean) {
ids.push(s.Stream.ID);
}
if (value)
store.markTagAdd(tagId, ids).catch((err: string) => {
EventBus.emit("showError", `Failed to add streams to tag: ${err}`);
store.markTagAdd(tagId, ids).catch((err: Error) => {
EventBus.emit(
"showError",
`Failed to add streams to tag: ${err.message}`,
);
});
else
store.markTagDel(tagId, ids).catch((err: string) => {
EventBus.emit("showError", `Failed to remove streams from tag: ${err}`);
store.markTagDel(tagId, ids).catch((err: Error) => {
EventBus.emit(
"showError",
`Failed to remove streams from tag: ${err.message}`,
);
});
}
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/SearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ watch(
);
onMounted(() => {
store.updateConverters().catch((err: string) => {
EventBus.emit("showError", `Failed to update converters: ${err}`);
store.updateConverters().catch((err: Error) => {
EventBus.emit("showError", `Failed to update converters: ${err.message}`);
});
const keyListener = (e: KeyboardEvent) => {
if (e.target === null || !(e.target instanceof Element)) return;
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/Status.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ onMounted(() => {
});
function updateStatus() {
store.updateStatus().catch((err: string) => {
EventBus.emit("showError", `Failed to update status: ${err}`);
store.updateStatus().catch((err: Error) => {
EventBus.emit("showError", `Failed to update status: ${err.message}`);
});
}
</script>
18 changes: 12 additions & 6 deletions web/src/components/Stream.vue
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ function changeConverter(converter: string) {

function fetchStreamForId() {
if (streamId.value !== null) {
stream.fetchStream(streamId.value, converter.value).catch((err: string) => {
EventBus.emit("showError", `Failed to fetch stream: ${err}`);
stream.fetchStream(streamId.value, converter.value).catch((err: Error) => {
EventBus.emit("showError", `Failed to fetch stream: ${err.message}`);
});
document.getSelection()?.empty();
}
Expand All @@ -559,12 +559,18 @@ function createMark() {

function markStream(tagId: string, value: boolean) {
if (value) {
store.markTagAdd(tagId, [streamId.value]).catch((err: string) => {
EventBus.emit("showError", `Failed to add stream to mark: ${err}`);
store.markTagAdd(tagId, [streamId.value]).catch((err: Error) => {
EventBus.emit(
"showError",
`Failed to add stream to mark: ${err.message}`,
);
});
} else {
store.markTagDel(tagId, [streamId.value]).catch((err: string) => {
EventBus.emit("showError", `Failed to remove stream from mark: ${err}`);
store.markTagDel(tagId, [streamId.value]).catch((err: Error) => {
EventBus.emit(
"showError",
`Failed to remove stream from mark: ${err.message}`,
);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/StreamData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const highlightRegex = (highlight: string[] | null) =>
return decoded;
});
return new RegExp(regex, "g");
} catch (e) {
} catch {
console.error(`Invalid regex: ${regex}`);
}
});
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/TagColorChangeDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ function updateColor() {
.then(() => {
visible.value = false;
})
.catch((err: string) => {
.catch((err: Error) => {
error.value = true;
loading.value = false;
EventBus.emit("showError", err);
EventBus.emit("showError", err.message);
});
}
</script>
4 changes: 2 additions & 2 deletions web/src/components/TagCreateDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ function createTag() {
.then(() => {
visible.value = false;
})
.catch((err: string) => {
.catch((err: Error) => {
error.value = true;
loading.value = false;
EventBus.emit("showError", err);
EventBus.emit("showError", err.message);
});
}
</script>
4 changes: 2 additions & 2 deletions web/src/components/TagDefinitionChangeDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ function updateDefinition() {
.then(() => {
visible.value = false;
})
.catch((err: string) => {
.catch((err: Error) => {
error.value = true;
loading.value = false;
EventBus.emit("showError", err);
EventBus.emit("showError", err.message);
});
}
</script>
4 changes: 2 additions & 2 deletions web/src/components/TagDeleteDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ function deleteTag() {
.then(() => {
visible.value = false;
})
.catch((err: string) => {
.catch((err: Error) => {
error.value = true;
loading.value = false;
EventBus.emit("showError", err);
EventBus.emit("showError", err.message);
});
}
</script>
4 changes: 2 additions & 2 deletions web/src/components/TagNameChangeDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ function updateName() {
.then(() => {
visible.value = false;
})
.catch((err: string) => {
.catch((err: Error) => {
error.value = true;
loading.value = false;
EventBus.emit("showError", err);
EventBus.emit("showError", err.message);
});
}
</script>
4 changes: 2 additions & 2 deletions web/src/components/TagSetConverterDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ function submitTagConverters() {
.then(() => {
visible.value = false;
})
.catch((err: string) => {
.catch((err: Error) => {
error.value = true;
loading.value = false;
EventBus.emit("showError", err);
EventBus.emit("showError", err.message);
});
}
</script>
4 changes: 2 additions & 2 deletions web/src/components/Tags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ onMounted(() => {
});
function updateTags() {
store.updateTags().catch((err: string) => {
EventBus.emit("showError", `Failed to update tags: ${err}`);
store.updateTags().catch((err: Error) => {
EventBus.emit("showError", `Failed to update tags: ${err.message}`);
});
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/stores/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const useGraphStore = defineStore("graph", {
this.graph = data;
this.running = false;
})
.catch((err) => {
.catch((err: unknown) => {
if (axios.isCancel(err)) return;
if (axios.isAxiosError<string, unknown>(err)) {
this.delta = delta;
Expand Down
Loading

0 comments on commit fd7e655

Please sign in to comment.