Skip to content

Commit

Permalink
last touch
Browse files Browse the repository at this point in the history
  • Loading branch information
williamsjokvist committed Nov 5, 2024
1 parent 6de8569 commit dff7c0c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
28 changes: 14 additions & 14 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ func NewCommandHandler(githubClient github.GithubClient, sqlDb *sql.Storage, nos
func (ch *CommandHandler) CheckForUpdate() (bool, error) {
currentVersion, err := version.NewVersion(ch.cfg.AppVersion)
if err != nil {
return false, model.NewError(model.ErrCheckForUpdate, err)
return false, model.WrapError(model.ErrCheckForUpdate, err)
}
latestVersion, err := ch.githubClient.GetLatestAppVersion()
if err != nil {
return false, model.NewError(model.ErrCheckForUpdate, err)
return false, model.WrapError(model.ErrCheckForUpdate, err)
}
return currentVersion.LessThan(latestVersion), nil
}

func (ch *CommandHandler) GetTranslation(locale string) (*locales.Localization, error) {
lng, err := i18n.GetTranslation(locale)
if err != nil {
return nil, model.NewError(model.ErrGetTranslations, err)
return nil, model.WrapError(model.ErrGetTranslations, err)
}
return lng, nil
}
Expand All @@ -68,11 +68,11 @@ func (ch *CommandHandler) OpenResultsDirectory() error {
switch runtime.GOOS {
case `darwin`:
if err := exec.Command(`Open`, `./results`).Run(); err != nil {
return model.NewError(model.ErrOpenResultsDirectory, err)
return model.WrapError(model.ErrOpenResultsDirectory, err)
}
case `windows`:
if err := exec.Command(`explorer.exe`, `.\results`).Run(); err != nil {
return model.NewError(model.ErrOpenResultsDirectory, err)
return model.WrapError(model.ErrOpenResultsDirectory, err)
}
}
return nil
Expand All @@ -81,31 +81,31 @@ func (ch *CommandHandler) OpenResultsDirectory() error {
func (ch *CommandHandler) GetSessions(userId, date string, limit uint8, offset uint16) ([]*model.Session, error) {
sessions, err := ch.sqlDb.GetSessions(context.Background(), userId, date, limit, offset)
if err != nil {
return nil, model.NewError(model.ErrGetSessions, err)
return nil, model.WrapError(model.ErrGetSessions, err)
}
return sessions, nil
}

func (ch *CommandHandler) GetSessionsStatistics(userId string) (*model.SessionsStatistics, error) {
sessionStatistics, err := ch.sqlDb.GetSessionsStatistics(context.Background(), userId)
if err != nil {
return nil, model.NewError(model.ErrGetSessionStatistics, err)
return nil, model.WrapError(model.ErrGetSessionStatistics, err)
}
return sessionStatistics, nil
}

func (ch *CommandHandler) GetMatches(sessionId uint16, userId string, limit uint8, offset uint16) ([]*model.Match, error) {
matches, err := ch.sqlDb.GetMatches(context.Background(), sessionId, userId, limit, offset)
if err != nil {
return nil, model.NewError(model.ErrGetMatches, err)
return nil, model.WrapError(model.ErrGetMatches, err)
}
return matches, nil
}

func (ch *CommandHandler) GetUsers() ([]*model.User, error) {
users, err := ch.sqlDb.GetUsers(context.Background())
if err != nil {
return nil, model.NewError(model.ErrGetUser, err)
return nil, model.WrapError(model.ErrGetUser, err)
}
return users, nil
}
Expand All @@ -128,7 +128,7 @@ func (ch *CommandHandler) GetThemes() ([]model.Theme, error) {
}
css, err := os.ReadFile(fmt.Sprintf(`themes/%s`, fileName))
if err != nil {
return nil, model.NewError(model.ErrReadThemeCSS, err)
return nil, model.WrapError(model.ErrReadThemeCSS, err)
}
name := strings.Split(fileName, `.css`)[0]

Expand All @@ -148,29 +148,29 @@ func (ch *CommandHandler) GetSupportedLanguages() []string {

func (ch *CommandHandler) SaveLocale(locale string) error {
if err := ch.nosqlDb.SaveLocale(locale); err != nil {
return model.NewError(model.ErrSaveLocale, err)
return model.WrapError(model.ErrSaveLocale, err)
}
return nil
}

func (ch *CommandHandler) GetGuiConfig() (*model.GuiConfig, error) {
guiCfg, err := ch.nosqlDb.GetGuiConfig()
if err != nil {
return nil, model.NewError(model.ErrGetGUIConfig, err)
return nil, model.WrapError(model.ErrGetGUIConfig, err)
}
return guiCfg, nil
}

func (ch *CommandHandler) SaveSidebarMinimized(sidebarMinified bool) error {
if err := ch.nosqlDb.SaveSidebarMinimized(sidebarMinified); err != nil {
return model.NewError(model.ErrSaveSidebarMinimized, err)
return model.WrapError(model.ErrSaveSidebarMinimized, err)
}
return nil
}

func (ch *CommandHandler) SaveTheme(theme model.ThemeName) error {
if err := ch.nosqlDb.SaveTheme(theme); err != nil {
return model.NewError(model.ErrSaveTheme, err)
return model.WrapError(model.ErrSaveTheme, err)
}
return nil
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,28 @@ func (ch *TrackingHandler) StartTracking(userCode string, restore bool) error {
if restore {
sesh, err := ch.sqlDb.GetLatestSession(ctx, userCode)
if err != nil {
return model.NewError(model.ErrGetLatestSession, err)
return model.WrapError(model.ErrGetLatestSession, err)
}
session = sesh
} else {
user, err := ch.sqlDb.GetUserByCode(ctx, userCode)
if err != nil && !errors.Is(err, sql.ErrUserNotFound) {
return model.NewError(model.ErrGetUser, err)
return model.WrapError(model.ErrGetUser, err)
}

if user == nil {
usr, err := ch.gameTracker.GetUser(ctx, userCode)
if err != nil {
return model.NewError(model.ErrGetUser, err)
return model.WrapError(model.ErrGetUser, err)
}
if err := ch.sqlDb.SaveUser(ctx, *usr); err != nil {
return model.NewError(model.ErrSaveUser, err)
return model.WrapError(model.ErrSaveUser, err)
}
}

sesh, err := ch.sqlDb.CreateSession(ctx, userCode)
if err != nil {
return model.NewError(model.ErrCreateSession, err)
return model.WrapError(model.ErrCreateSession, err)
}
session = sesh
// session.LP = bl.GetLP()
Expand Down Expand Up @@ -191,7 +191,7 @@ func (ch *TrackingHandler) SelectGame(game model.GameType) error {
username = ch.cfg.CapIDEmail
password = ch.cfg.CapIDPassword
default:
return model.NewError(model.ErrSelectGame, fmt.Errorf("game does not exist"))
return model.WrapError(model.ErrSelectGame, fmt.Errorf("game does not exist"))
}

authChan := make(chan tracker.AuthStatus)
Expand All @@ -200,7 +200,7 @@ func (ch *TrackingHandler) SelectGame(game model.GameType) error {
go ch.gameTracker.Authenticate(ctx, username, password, authChan)
for status := range authChan {
if status.Err != nil {
return model.NewError(model.ErrAuth, status.Err)
return model.WrapError(model.ErrAuth, status.Err)
}

ch.eventEmitter("auth-progress", status.Progress)
Expand Down
2 changes: 0 additions & 2 deletions gui/wailsjs/go/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ export namespace model {
export class FGCTrackerError {
localizationKey: ErrorLocalizationKey;
message: string;
InnerError: any;

static createFrom(source: any = {}) {
return new FGCTrackerError(source);
Expand All @@ -279,7 +278,6 @@ export namespace model {
if ('string' === typeof source) source = JSON.parse(source);
this.localizationKey = source["localizationKey"];
this.message = source["message"];
this.InnerError = source["InnerError"];
}
}
export class GuiConfig {
Expand Down
9 changes: 2 additions & 7 deletions pkg/model/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ var (
type FGCTrackerError struct {
LocalizationKey ErrorLocalizationKey `json:"localizationKey"`
Message string `json:"message"`
InnerError error
InnerError error `json:"-"`
}

func NewError(fmtErr *FGCTrackerError, err error) *FGCTrackerError {
func WrapError(fmtErr *FGCTrackerError, err error) *FGCTrackerError {
return &FGCTrackerError{
LocalizationKey: fmtErr.LocalizationKey,
Message: fmtErr.Message,
Expand All @@ -102,11 +102,6 @@ func (e *FGCTrackerError) Unwrap() error {
return e.InnerError
}

func ContainsFGCTrackerError(err error) bool {
var trackingErr *FGCTrackerError
return errors.As(err, &trackingErr)
}

func FormatError(err error) any {
var formattedErr *FGCTrackerError
if errors.As(err, &formattedErr) {
Expand Down

0 comments on commit dff7c0c

Please sign in to comment.