Skip to content

Commit

Permalink
fix sentry version and message
Browse files Browse the repository at this point in the history
  • Loading branch information
zulkhair committed Oct 9, 2024
1 parent 9888454 commit f8d2183
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 105 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ builds:
- -X main.AppVersion={{.Version}}
- -X main.SentryDsn={{.Env.SENTRY_DSN}}
- -X main.PosthogAPIKey={{.Env.POSTHOG_API_KEY}}
- -X main.Env=PROD
goos:
- linux
- windows
Expand Down
4 changes: 3 additions & 1 deletion cmd/world/cardinal/cardinal.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ var BaseCmd = &cobra.Command{
dependency.DockerDaemon,
)
},
Run: func(cmd *cobra.Command, _ []string) {
RunE: func(cmd *cobra.Command, _ []string) error {

Check warning on line 26 in cmd/world/cardinal/cardinal.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/cardinal/cardinal.go#L26

Added line #L26 was not covered by tests
if err := cmd.Help(); err != nil {
logger.Fatalf("Failed to execute cardinal command : %s", err.Error())
return err

Check warning on line 29 in cmd/world/cardinal/cardinal.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/cardinal/cardinal.go#L29

Added line #L29 was not covered by tests
}
return nil

Check warning on line 31 in cmd/world/cardinal/cardinal.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/cardinal/cardinal.go#L31

Added line #L31 was not covered by tests
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/world/cardinal/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var devCmd = &cobra.Command{
return err
}

cfg, err := config.GetConfig(cmd)
cfg, err := config.GetConfig()
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/world/cardinal/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var purgeCmd = &cobra.Command{
Long: `Stop and reset the state of your Cardinal game shard.
This command stop all Docker services and remove all Docker volumes.`,
RunE: func(cmd *cobra.Command, _ []string) error {
cfg, err := config.GetConfig(cmd)
cfg, err := config.GetConfig()
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/world/cardinal/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This will restart the following Docker services:
- Cardinal (Core game logic)
- Nakama (Relay)`,
RunE: func(cmd *cobra.Command, _ []string) error {
cfg, err := config.GetConfig(cmd)
cfg, err := config.GetConfig()
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/world/cardinal/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ This will start the following Docker services and its dependencies:
- Nakama (Relay)
- Redis (Cardinal dependency)`,
RunE: func(cmd *cobra.Command, _ []string) error {
cfg, err := config.GetConfig(cmd)
cfg, err := config.GetConfig()
if err != nil {
return err
}
Expand All @@ -85,7 +85,7 @@ This will start the following Docker services and its dependencies:
if logLevel != "" {
zeroLogLevel, err := zerolog.ParseLevel(logLevel)
if err != nil {
return fmt.Errorf("invalid value for flag %s: must be one of (%v)", flagLogLevel, validLogLevels)
return eris.Errorf("invalid value for flag %s: must be one of (%v)", flagLogLevel, validLogLevels)

Check warning on line 88 in cmd/world/cardinal/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/cardinal/start.go#L88

Added line #L88 was not covered by tests
}
cfg.DockerEnv[DockerCardinalEnvLogLevel] = zeroLogLevel.String()
}
Expand All @@ -96,7 +96,7 @@ This will start the following Docker services and its dependencies:
} else if _, err := zerolog.ParseLevel(cfg.DockerEnv[DockerCardinalEnvLogLevel]); err != nil {
// make sure the log level is valid when the flag is not set and using env var from config
// Error when CARDINAL_LOG_LEVEL is not a valid log level
return fmt.Errorf("invalid value for %s env variable in the config file: must be one of (%v)",
return eris.Errorf("invalid value for %s env variable in the config file: must be one of (%v)",

Check warning on line 99 in cmd/world/cardinal/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/cardinal/start.go#L99

Added line #L99 was not covered by tests
DockerCardinalEnvLogLevel, validLogLevels)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/world/cardinal/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This will stop the following Docker services:
- Nakama (Relay) + DB
- Redis (Cardinal dependency)`,
RunE: func(cmd *cobra.Command, _ []string) error {
cfg, err := config.GetConfig(cmd)
cfg, err := config.GetConfig()
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/world/evm/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var startCmd = &cobra.Command{
Short: "Start the EVM base shard. Use --da-auth-token to pass in an auth token directly.",
Long: "Start the EVM base shard. Requires connection to celestia DA.",
RunE: func(cmd *cobra.Command, _ []string) error {
cfg, err := config.GetConfig(cmd)
cfg, err := config.GetConfig()
if err != nil {
return err
}
Expand Down Expand Up @@ -52,7 +52,7 @@ var startCmd = &cobra.Command{

err = dockerClient.Start(cmd.Context(), service.EVM)
if err != nil {
return fmt.Errorf("error starting %s docker container: %w", teacmd.DockerServiceEVM, err)
return eris.Wrapf(err, "error starting %s docker container", teacmd.DockerServiceEVM)

Check warning on line 55 in cmd/world/evm/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/evm/start.go#L55

Added line #L55 was not covered by tests
}

// Stop the DA service if it was started in dev mode
Expand Down Expand Up @@ -82,7 +82,7 @@ func validateDevDALayer(ctx context.Context, cfg *config.Config, dockerClient *d
cfg.Timeout = -1
logger.Println("starting DA docker service for dev mode...")
if err := dockerClient.Start(ctx, service.CelestiaDevNet); err != nil {
return fmt.Errorf("error starting %s docker container: %w", daService, err)
return eris.Wrapf(err, "error starting %s docker container", daService)

Check warning on line 85 in cmd/world/evm/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/evm/start.go#L85

Added line #L85 was not covered by tests
}
logger.Println("started DA service...")

Expand Down Expand Up @@ -115,12 +115,12 @@ func validateProdDALayer(cfg *config.Config) error {
if len(cfg.DockerEnv[env]) > 0 {
continue
}
errs = append(errs, fmt.Errorf("missing %q", env))
errs = append(errs, eris.Errorf("missing %q", env))

Check warning on line 118 in cmd/world/evm/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/evm/start.go#L118

Added line #L118 was not covered by tests
}
if len(errs) > 0 {
// Prepend an error describing the overall problem
errs = append([]error{
errors.New("the [evm] section of your config is missing some required variables"),
eris.New("the [evm] section of your config is missing some required variables"),

Check warning on line 123 in cmd/world/evm/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/evm/start.go#L123

Added line #L123 was not covered by tests
}, errs...)
return errors.Join(errs...)
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func getDAToken(ctx context.Context, cfg *config.Config, dockerClient *docker.Cl
}

if token == "" {
return "", errors.New("got empty DA token")
return "", eris.New("got empty DA token")

Check warning on line 172 in cmd/world/evm/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/evm/start.go#L172

Added line #L172 was not covered by tests
}
return token, nil
}
2 changes: 1 addition & 1 deletion cmd/world/evm/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var stopCmd = &cobra.Command{
Short: "Stop the EVM base shard and DA layer client.",
Long: "Stop the EVM base shard and data availability layer client if they are running.",
RunE: func(cmd *cobra.Command, _ []string) error {
cfg, err := config.GetConfig(cmd)
cfg, err := config.GetConfig()

Check warning on line 18 in cmd/world/evm/stop.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/evm/stop.go#L18

Added line #L18 was not covered by tests
if err != nil {
return err
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/world/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var (
AppVersion string
PosthogAPIKey string
SentryDsn string
Env string
)

func init() {
Expand All @@ -27,16 +28,17 @@ func init() {
AppVersion = "v0.0.1-dev"
}
root.AppVersion = AppVersion

if Env == "" {
Env = "DEV"

Check warning on line 33 in cmd/world/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/main.go#L32-L33

Added lines #L32 - L33 were not covered by tests
}
}

func main() {
// Sentry initialization
telemetry.SentryInit(SentryDsn)
telemetry.SentryInit(SentryDsn, Env, AppVersion)

Check warning on line 39 in cmd/world/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/main.go#L39

Added line #L39 was not covered by tests
defer telemetry.SentryFlush()

// Set logger sentry hook
log.Logger = log.Logger.Hook(telemetry.SentryHook{})

// Set up config directory "~/.worldcli/"
err := globalconfig.SetupConfigDir()
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion cmd/world/root/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var DoctorDeps = []dependency.Dependency{
dependency.Git,
dependency.Go,
dependency.Docker,
dependency.DockerCompose,
dependency.DockerDaemon,
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/world/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package root
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -13,6 +12,7 @@ import (
"time"

"github.com/charmbracelet/lipgloss"
"github.com/getsentry/sentry-go"
"github.com/hashicorp/go-version"
"github.com/rotisserie/eris"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -95,7 +95,7 @@ func checkLatestVersion() error {
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
logger.Debug(eris.Wrap(errors.New("status is not 200"), "error fetching the latest release"))
logger.Debug(eris.Wrap(eris.New("status is not 200"), "error fetching the latest release"))

Check warning on line 98 in cmd/world/root/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/root/root.go#L98

Added line #L98 was not covered by tests
return nil
}

Expand Down Expand Up @@ -139,6 +139,7 @@ func checkLatestVersion() error {
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
sentry.CaptureException(err)

Check warning on line 142 in cmd/world/root/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/root/root.go#L142

Added line #L142 was not covered by tests
logger.Errors(err)
}
// print log stack
Expand Down
8 changes: 3 additions & 5 deletions cmd/world/root/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package root
import (
"bytes"
"context"
"errors"
"fmt"
"net"
"os"
"strings"
"testing"
"time"

"github.com/rotisserie/eris"
"github.com/spf13/cobra"
"gotest.tools/v3/assert"
)
Expand All @@ -34,12 +33,12 @@ func outputFromCmd(cobra *cobra.Command, cmd string) ([]string, error) {
}()

if err := cobra.Execute(); err != nil {
return nil, fmt.Errorf("root command failed with: %w", err)
return nil, eris.Errorf("root command failed with: %v", err)
}
lines := strings.Split(stdOut.String(), "\n")
errorStr := stdErr.String()
if len(errorStr) > 0 {
return lines, errors.New(errorStr)
return lines, eris.New(errorStr)
}

return lines, nil
Expand Down Expand Up @@ -78,7 +77,6 @@ func TestExecuteDoctorCommand(t *testing.T) {
"Git": 0,
"Go": 0,
"Docker": 0,
"Docker Compose": 0,
"Docker daemon is running": 0,
}

Expand Down
26 changes: 12 additions & 14 deletions common/config/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package config

import (
"errors"
"fmt"
"os"
"path"
"path/filepath"

"github.com/pelletier/go-toml"
"github.com/rotisserie/eris"
"github.com/spf13/cobra"

"pkg.world.dev/world-cli/common/logger"
Expand All @@ -25,6 +25,8 @@ var (
// running docker. An error will be generated if a duplicate key is found across
// these sections.
dockerEnvHeaders = []string{"cardinal", "evm", "nakama", "common"}

configFile string // Config file flag value
)

type Config struct {
Expand All @@ -39,11 +41,11 @@ type Config struct {
}

func AddConfigFlag(cmd *cobra.Command) {
cmd.PersistentFlags().String(flagForConfigFile, "", "a toml encoded config file")
cmd.PersistentFlags().StringVarP(&configFile, flagForConfigFile, "c", "", "a toml encoded config file")
}

func GetConfig(cmd *cobra.Command) (*Config, error) {
cfg, err := findAndLoadConfigFile(cmd)
func GetConfig() (*Config, error) {
cfg, err := findAndLoadConfigFile()
if err != nil {
return nil, err
}
Expand All @@ -58,13 +60,9 @@ func GetConfig(cmd *cobra.Command) (*Config, error) {
// 2. A config file set via an environment variable
// 3. A config file named "world.toml" in the current directory
// 4. A config file found in a parent directory.
func findAndLoadConfigFile(cmd *cobra.Command) (*Config, error) {
func findAndLoadConfigFile() (*Config, error) {
// First look for the config file in the config file flag.
if cmd.PersistentFlags().Changed(flagForConfigFile) {
configFile, err := cmd.PersistentFlags().GetString(flagForConfigFile)
if err != nil {
return nil, err
}
if configFile != "" {
return loadConfigFromFile(configFile)
}

Expand Down Expand Up @@ -94,7 +92,7 @@ func findAndLoadConfigFile(cmd *cobra.Command) (*Config, error) {
}
}

return nil, errors.New("no config file found")
return nil, eris.Errorf("No config file found, config flag value: %s, curr dir: %s", configFile, currDir)
}

func loadConfigFromFile(filename string) (*Config, error) {
Expand All @@ -114,7 +112,7 @@ func loadConfigFromFile(filename string) (*Config, error) {
if rootDir, ok := data["root_dir"]; ok {
cfg.RootDir, ok = rootDir.(string)
if !ok {
return nil, errors.New("root_dir must be a string")
return nil, eris.New("root_dir must be a string")

Check warning on line 115 in common/config/config.go

View check run for this annotation

Codecov / codecov/patch

common/config/config.go#L115

Added line #L115 was not covered by tests
}
} else {
cfg.RootDir, _ = filepath.Split(filename)
Expand All @@ -124,7 +122,7 @@ func loadConfigFromFile(filename string) (*Config, error) {
if gameDir, ok := data["game_dir"]; ok {
cfg.GameDir, ok = gameDir.(string)
if !ok {
return nil, errors.New("game_dir must be a string")
return nil, eris.New("game_dir must be a string")

Check warning on line 125 in common/config/config.go

View check run for this annotation

Codecov / codecov/patch

common/config/config.go#L125

Added line #L125 was not covered by tests
}
} else {
cfg.GameDir = "cardinal"
Expand All @@ -137,7 +135,7 @@ func loadConfigFromFile(filename string) (*Config, error) {
}
for key, val := range m.(map[string]any) {
if _, ok := cfg.DockerEnv[key]; ok {
return nil, fmt.Errorf("duplicate env variable %q", key)
return nil, eris.Errorf("duplicate env variable %q", key)
}
cfg.DockerEnv[key] = fmt.Sprintf("%v", val)
}
Expand Down
Loading

0 comments on commit f8d2183

Please # to comment.