From 99bc0378cb06c5df3e48f4c0db49f157221f2080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Sj=C3=B6kvist?= Date: Tue, 5 Nov 2024 18:58:16 +0100 Subject: [PATCH] domain name error --- cmd/cmd.go | 2 +- gui/src/main/app-error.tsx | 16 +++++++------- gui/src/main/error-popup.tsx | 6 +++--- gui/src/state/auth-machine.ts | 2 +- gui/src/state/tracking-machine.ts | 2 +- gui/wailsjs/go/cmd/CommandHandler.d.ts | 2 +- gui/wailsjs/go/models.ts | 8 +++---- pkg/model/error.go | 30 +++++++++++++------------- 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index bec9423..7a2d549 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -175,6 +175,6 @@ func (ch *CommandHandler) SaveTheme(theme model.ThemeName) error { return nil } -func (ch *CommandHandler) GetFormattedErrorModelUnused() *model.FormattedError { +func (ch *CommandHandler) GetFGCTrackerErrorModelUnused() *model.FGCTrackerError { return nil } diff --git a/gui/src/main/app-error.tsx b/gui/src/main/app-error.tsx index a9aff94..27814d3 100644 --- a/gui/src/main/app-error.tsx +++ b/gui/src/main/app-error.tsx @@ -11,7 +11,7 @@ import { AppTitleBar } from './app-titlebar' import { LocalizationKey } from './i18n' export function AppErrorBoundary() { - const err = useFormattedError() + const err = useFGCTrackerError() return ( @@ -21,7 +21,7 @@ export function AppErrorBoundary() { export function PageErrorBoundary() { const { t } = useTranslation() - const err = useFormattedError() + const err = useFGCTrackerError() if (!err?.localizationKey) { return null } @@ -34,25 +34,25 @@ export function PageErrorBoundary() { ) } -const isFormattedError = (error: unknown) => error instanceof Object && 'translationKey' in error +const isFGCTrackerError = (error: unknown) => error instanceof Object && 'translationKey' in error -function useFormattedError() { +function useFGCTrackerError() { const thrownError = useRouteError() - const [err, setErr] = React.useState() + const [err, setErr] = React.useState() React.useEffect(() => { console.error(thrownError) if (thrownError instanceof Error) { setErr({ translationKey: '', message: thrownError.message, error: thrownError }) - } else if (isFormattedError(thrownError)) { + } else if (isFGCTrackerError(thrownError)) { setErr(thrownError) } }, [thrownError]) - return err as model.FormattedError + return err as model.FGCTrackerError } -function ErrorWrapper(props: React.PropsWithChildren & { err?: model.FormattedError }) { +function ErrorWrapper(props: React.PropsWithChildren & { err?: model.FGCTrackerError }) { const { t } = useTranslation() if (!props.err) { return null diff --git a/gui/src/main/error-popup.tsx b/gui/src/main/error-popup.tsx index 18c67f6..1d55a21 100644 --- a/gui/src/main/error-popup.tsx +++ b/gui/src/main/error-popup.tsx @@ -9,8 +9,8 @@ import { cn } from '@/helpers/cn' import type { LocalizationKey } from './i18n' type ErrorContextType = [ - error: model.FormattedError | null, - setError: React.Dispatch + error: model.FGCTrackerError | null, + setError: React.Dispatch ] const ErrorContext = React.createContext(null) export const useErrorPopup = () => React.useContext(ErrorContext)![1] @@ -18,7 +18,7 @@ export const useErrorPopup = () => React.useContext(ErrorContext)![1] export function ErrorPopupProvider(props: React.PropsWithChildren) { const { t } = useTranslation() const [scope, animate] = useAnimate() - const [error, setError] = React.useState(null) + const [error, setError] = React.useState(null) React.useEffect(() => { if (error === null) { diff --git a/gui/src/state/auth-machine.ts b/gui/src/state/auth-machine.ts index 1217399..f7de14a 100644 --- a/gui/src/state/auth-machine.ts +++ b/gui/src/state/auth-machine.ts @@ -10,7 +10,7 @@ import { TRACKING_MACHINE } from './tracking-machine' type AuthMachineContextProps = { progress: number game?: model.GameType - error: model.FormattedError | null + error: model.FGCTrackerError | null } export const AUTH_MACHINE = setup({ types: { diff --git a/gui/src/state/tracking-machine.ts b/gui/src/state/tracking-machine.ts index f560908..2973fda 100644 --- a/gui/src/state/tracking-machine.ts +++ b/gui/src/state/tracking-machine.ts @@ -10,7 +10,7 @@ type TrackingMachineContextProps = { restore: boolean isTracking: boolean match: model.Match - error: model.FormattedError | null + error: model.FGCTrackerError | null } export const TRACKING_MACHINE = setup({ diff --git a/gui/wailsjs/go/cmd/CommandHandler.d.ts b/gui/wailsjs/go/cmd/CommandHandler.d.ts index 01ea292..bd2cc0c 100755 --- a/gui/wailsjs/go/cmd/CommandHandler.d.ts +++ b/gui/wailsjs/go/cmd/CommandHandler.d.ts @@ -7,7 +7,7 @@ export function CheckForUpdate():Promise; export function GetAppVersion():Promise; -export function GetFormattedErrorModelUnused():Promise; +export function GetFGCTrackerErrorModelUnused():Promise; export function GetGuiConfig():Promise; diff --git a/gui/wailsjs/go/models.ts b/gui/wailsjs/go/models.ts index 6adbdcf..d31492e 100755 --- a/gui/wailsjs/go/models.ts +++ b/gui/wailsjs/go/models.ts @@ -260,20 +260,20 @@ export namespace model { errOpenResultsDirectory = "errOpenResultsDirectory", errReadThemeCSS = "errReadThemeCSS", } - export class FormattedError { + export class FGCTrackerError { localizationKey: ErrorLocalizationKey; message: string; - error: any; + InnerError: any; static createFrom(source: any = {}) { - return new FormattedError(source); + return new FGCTrackerError(source); } constructor(source: any = {}) { if ('string' === typeof source) source = JSON.parse(source); this.localizationKey = source["localizationKey"]; this.message = source["message"]; - this.error = source["error"]; + this.InnerError = source["InnerError"]; } } export class GuiConfig { diff --git a/pkg/model/error.go b/pkg/model/error.go index c7ee7c1..09aae6d 100644 --- a/pkg/model/error.go +++ b/pkg/model/error.go @@ -67,43 +67,43 @@ var ( ErrReadThemeCSS = newError(tKeyErrReadThemeCSS, errors.New("read theme css")) ) -type FormattedError struct { - ErrorLocalizationKey ErrorLocalizationKey `json:"localizationKey"` - Message string `json:"message"` - InnerError error `json:"error"` +type FGCTrackerError struct { + LocalizationKey ErrorLocalizationKey `json:"localizationKey"` + Message string `json:"message"` + InnerError error } -func NewError(fmtErr *FormattedError, err error) *FormattedError { +func NewError(fmtErr *FGCTrackerError, err error) *FGCTrackerError { fmtErr.InnerError = fmt.Errorf("%w: %w", fmtErr.InnerError, err) return fmtErr } -func newError(key ErrorLocalizationKey, err error) *FormattedError { - return &FormattedError{ - ErrorLocalizationKey: key, - InnerError: err, +func newError(key ErrorLocalizationKey, err error) *FGCTrackerError { + return &FGCTrackerError{ + LocalizationKey: key, + InnerError: err, } } -func (e *FormattedError) Error() string { +func (e *FGCTrackerError) Error() string { return e.InnerError.Error() } -func (e *FormattedError) Unwrap() error { +func (e *FGCTrackerError) Unwrap() error { return e.InnerError } -func ContainsFormattedError(err error) bool { - var trackingErr *FormattedError +func ContainsFGCTrackerError(err error) bool { + var trackingErr *FGCTrackerError return errors.As(err, &trackingErr) } func FormatError(err error) any { - var formattedErr *FormattedError + var formattedErr *FGCTrackerError var message string var localizationKey ErrorLocalizationKey if errors.As(err, &formattedErr) { - localizationKey = formattedErr.ErrorLocalizationKey + localizationKey = formattedErr.LocalizationKey message = formattedErr.InnerError.Error() }