summaryrefslogtreecommitdiff
path: root/frontend/src/utils
diff options
context:
space:
mode:
authorAAGaming <aagaming@riseup.net>2024-05-27 17:21:27 -0400
committerAAGaming <aagaming@riseup.net>2024-05-27 17:21:27 -0400
commit9c8db576f5cea498c70d00a0764d7f3c6c9cef65 (patch)
tree72436ef52123e6343cdcc21b66efd59b51c4de23 /frontend/src/utils
parenta84a13c76d99f1e6f4505d43108a4111749e5035 (diff)
downloaddecky-loader-9c8db576f5cea498c70d00a0764d7f3c6c9cef65.tar.gz
decky-loader-9c8db576f5cea498c70d00a0764d7f3c6c9cef65.zip
error boundary now properly reports steam errors
Diffstat (limited to 'frontend/src/utils')
-rw-r--r--frontend/src/utils/errors.ts48
1 files changed, 48 insertions, 0 deletions
diff --git a/frontend/src/utils/errors.ts b/frontend/src/utils/errors.ts
new file mode 100644
index 00000000..0bf82986
--- /dev/null
+++ b/frontend/src/utils/errors.ts
@@ -0,0 +1,48 @@
+import { ErrorInfo } from 'react';
+
+const pluginErrorRegex = /http:\/\/localhost:1337\/plugins\/([^\/]*)\//;
+const pluginSourceMapErrorRegex = /decky:\/\/decky\/plugin\/([^\/]*)\//;
+const legacyPluginErrorRegex = /decky:\/\/decky\/legacy_plugin\/([^\/]*)\/index.js/;
+
+export interface ValveReactErrorInfo {
+ error: Error;
+ info: ErrorInfo;
+}
+
+export interface ValveError {
+ identifier: string;
+ identifierHash: string;
+ message: string | [func: string, src: string, line: number, column: number];
+}
+
+export type ErrorSource = [source: string, wasPlugin: boolean, shouldReportToValve: boolean];
+
+export function getLikelyErrorSourceFromValveError(error: ValveError): ErrorSource {
+ return getLikelyErrorSource(JSON.stringify(error?.message));
+}
+
+export function getLikelyErrorSourceFromValveReactError(error: ValveReactErrorInfo): ErrorSource {
+ return getLikelyErrorSource(error?.error?.stack);
+}
+
+export function getLikelyErrorSource(error?: string): ErrorSource {
+ const pluginMatch = error?.match(pluginErrorRegex);
+ if (pluginMatch) {
+ return [decodeURIComponent(pluginMatch[1]), true, false];
+ }
+
+ const pluginMatchViaMap = error?.match(pluginSourceMapErrorRegex);
+ if (pluginMatchViaMap) {
+ return [decodeURIComponent(pluginMatchViaMap[1]), true, false];
+ }
+
+ const legacyPluginMatch = error?.match(legacyPluginErrorRegex);
+ if (legacyPluginMatch) {
+ return [decodeURIComponent(legacyPluginMatch[1]), true, false];
+ }
+
+ if (error?.includes('http://localhost:1337/')) {
+ return ['the Decky frontend', false, false];
+ }
+ return ['Steam', false, true];
+}