Skip to content

Commit

Permalink
Auto reload page on error for prod builds
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmacdonald committed Feb 22, 2024
1 parent a184b13 commit a738b58
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
5 changes: 3 additions & 2 deletions console.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main
import (
"context"
"errors"
"github.com/nxadm/tail"
"io"
"log/slog"
"runtime"
"strings"
"sync"

"github.com/nxadm/tail"
)

type logIngest struct {
Expand Down Expand Up @@ -83,7 +84,7 @@ func (li *logIngest) lineEmitter(ctx context.Context, incoming chan string) {
}
}

// startIngest begins reading incoming log events, parsing events from the lines and emitting any found events as a LogEvent
// startIngest begins reading incoming log events, parsing events from the lines and emitting any found events as a LogEvent.
func (li *logIngest) startIngest(ctx context.Context) {
defer li.tail.Cleanup()
incomingLogLines := make(chan string)
Expand Down
1 change: 0 additions & 1 deletion events.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,5 @@ func (e eventHandler) start(ctx context.Context) {
case <-ctx.Done():
return
}

}
}
7 changes: 6 additions & 1 deletion frontend/src/component/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ export class ErrorBoundary extends Component<BoundaryProps, BoundaryState> {

render(): ReactNode {
if (this.state.hasError) {
if (import.meta.env.PROD) {
setInterval(() => window.location.reload(), 5000);
}

return (
<Typography
marginTop={3}
variant={'h2'}
color={'error'}
textAlign={'center'}
>
🤯 🤯 🤯 Something went wrong 🤯 🤯 🤯
🤯 🤯 🤯 Something went wrong, reloading in 5 seconds... 🤯
🤯 🤯
</Typography>
);
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
2 changes: 1 addition & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/dotse/slug"
)

// tailLogAdapter implements a tail.logger interface using log/slog
// tailLogAdapter implements a tail.logger interface using log/slog.
type tailLogAdapter struct {
echo bool
}
Expand Down
3 changes: 2 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main
import (
"errors"
"fmt"
"github.com/leighmacdonald/steamid/v3/steamid"
"log/slog"
"regexp"
"strconv"
"strings"
"time"

"github.com/leighmacdonald/steamid/v3/steamid"
)

var ErrNoMatch = errors.New("no match found")
Expand Down
7 changes: 4 additions & 3 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"errors"
"fmt"
"log/slog"
"modernc.org/sqlite"
sqlite3 "modernc.org/sqlite/lib"
"net"
"strings"
"sync"
Expand All @@ -17,6 +15,8 @@ import (
"github.com/leighmacdonald/bd/store"
"github.com/leighmacdonald/steamid/v3/steamid"
"github.com/leighmacdonald/steamweb/v2"
"modernc.org/sqlite"
sqlite3 "modernc.org/sqlite/lib"
)

var errPlayerNotFound = errors.New("player not found")
Expand Down Expand Up @@ -406,7 +406,8 @@ func (s *gameState) onStatus(ctx context.Context, steamID steamid.SID64, evt sta
CreatedOn: time.Now(),
})
if errAddName != nil {
if sqliteErr, ok := errAddName.(*sqlite.Error); ok {
var sqliteErr *sqlite.Error
if errors.As(errAddName, &sqliteErr) {
if sqliteErr.Code() != sqlite3.SQLITE_CONSTRAINT_PRIMARYKEY {
slog.Error("Could not save new user name", errAttr(errAddName))
}
Expand Down

0 comments on commit a738b58

Please sign in to comment.