Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't panic #377

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (c *Config) LoadDefaults(ctx context.Context) {
if err != nil {
span.RecordError(err)
span.End()
log.Panic(fmt.Errorf("failed to unmarshal global configuration: %w", err))
log.Fatal(fmt.Errorf("failed to unmarshal global configuration: %w", err))
}

for configObject, configMap := range gconf {
Expand Down Expand Up @@ -194,15 +194,15 @@ func (c *Config) LoadDefaults(ctx context.Context) {
err := fmt.Errorf("unknown config object: %s", configObject)
span.RecordError(err)
span.End()
log.Panic(err)
log.Fatal(err)
}
}
}
}
} else if !os.IsNotExist(err) {
span.RecordError(err)
span.End()
log.Panic(fmt.Errorf("failed to read global configuration file: %w", err))
log.Fatal(fmt.Errorf("failed to read global configuration file: %w", err))
}

c.pluginDefaults = PluginConfig{
Expand All @@ -222,15 +222,15 @@ func (c *Config) LoadDefaults(ctx context.Context) {
if err := c.GlobalKoanf.Load(structs.Provider(c.globalDefaults, "json"), nil); err != nil {
span.RecordError(err)
span.End()
log.Panic(fmt.Errorf("failed to load default global configuration: %w", err))
log.Fatal(fmt.Errorf("failed to load default global configuration: %w", err))
}
}

if c.PluginKoanf != nil {
if err := c.PluginKoanf.Load(structs.Provider(c.pluginDefaults, "json"), nil); err != nil {
span.RecordError(err)
span.End()
log.Panic(fmt.Errorf("failed to load default plugin configuration: %w", err))
log.Fatal(fmt.Errorf("failed to load default plugin configuration: %w", err))
}
}

Expand All @@ -245,7 +245,7 @@ func (c *Config) LoadGlobalEnvVars(ctx context.Context) {
if err := c.GlobalKoanf.Load(loadEnvVars(), nil); err != nil {
span.RecordError(err)
span.End()
log.Panic(fmt.Errorf("failed to load environment variables: %w", err))
log.Fatal(fmt.Errorf("failed to load environment variables: %w", err))
}

span.End()
Expand All @@ -259,7 +259,7 @@ func (c *Config) LoadPluginEnvVars(ctx context.Context) {
if err := c.PluginKoanf.Load(loadEnvVars(), nil); err != nil {
span.RecordError(err)
span.End()
log.Panic(fmt.Errorf("failed to load environment variables: %w", err))
log.Fatal(fmt.Errorf("failed to load environment variables: %w", err))
}

span.End()
Expand All @@ -278,7 +278,7 @@ func (c *Config) LoadGlobalConfigFile(ctx context.Context) {
if err := c.GlobalKoanf.Load(file.Provider(c.globalConfigFile), yaml.Parser()); err != nil {
span.RecordError(err)
span.End()
log.Panic(fmt.Errorf("failed to load global configuration: %w", err))
log.Fatal(fmt.Errorf("failed to load global configuration: %w", err))
}

span.End()
Expand All @@ -291,7 +291,7 @@ func (c *Config) LoadPluginConfigFile(ctx context.Context) {
if err := c.PluginKoanf.Load(file.Provider(c.pluginConfigFile), yaml.Parser()); err != nil {
span.RecordError(err)
span.End()
log.Panic(fmt.Errorf("failed to load plugin configuration: %w", err))
log.Fatal(fmt.Errorf("failed to load plugin configuration: %w", err))
}

span.End()
Expand All @@ -306,7 +306,7 @@ func (c *Config) UnmarshalGlobalConfig(ctx context.Context) {
}); err != nil {
span.RecordError(err)
span.End()
log.Panic(fmt.Errorf("failed to unmarshal global configuration: %w", err))
log.Fatal(fmt.Errorf("failed to unmarshal global configuration: %w", err))
}

span.End()
Expand All @@ -321,7 +321,7 @@ func (c *Config) UnmarshalPluginConfig(ctx context.Context) {
}); err != nil {
span.RecordError(err)
span.End()
log.Panic(fmt.Errorf("failed to unmarshal plugin configuration: %w", err))
log.Fatal(fmt.Errorf("failed to unmarshal plugin configuration: %w", err))
}

span.End()
Expand All @@ -335,15 +335,15 @@ func (c *Config) MergeGlobalConfig(
if err := c.GlobalKoanf.Load(confmap.Provider(updatedGlobalConfig, "."), nil); err != nil {
span.RecordError(err)
span.End()
log.Panic(fmt.Errorf("failed to merge global configuration: %w", err))
log.Fatal(fmt.Errorf("failed to merge global configuration: %w", err))
}

if err := c.GlobalKoanf.UnmarshalWithConf("", &c.Global, koanf.UnmarshalConf{
Tag: "json",
}); err != nil {
span.RecordError(err)
span.End()
log.Panic(fmt.Errorf("failed to unmarshal global configuration: %w", err))
log.Fatal(fmt.Errorf("failed to unmarshal global configuration: %w", err))
}

span.End()
Expand All @@ -356,7 +356,7 @@ func (c *Config) ValidateGlobalConfig(ctx context.Context) {
if err := c.GlobalKoanf.Unmarshal("", &globalConfig); err != nil {
span.RecordError(err)
span.End()
log.Panic(
log.Fatal(
gerr.ErrValidationFailed.Wrap(
fmt.Errorf("failed to unmarshal global configuration: %w", err)),
)
Expand Down Expand Up @@ -466,6 +466,6 @@ func (c *Config) ValidateGlobalConfig(ctx context.Context) {
}
span.RecordError(fmt.Errorf("failed to validate global configuration"))
span.End()
log.Panic("failed to validate global configuration")
log.Fatal("failed to validate global configuration")
}
}
4 changes: 2 additions & 2 deletions logging/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func NewLogger(ctx context.Context, cfg LoggerConfig) zerolog.Logger {
if err != nil {
span.RecordError(err)
span.End()
log.Panic(err)
log.Fatal(err)
}
outputs = append(outputs, syslogWriter)
case config.RSyslog:
Expand All @@ -82,7 +82,7 @@ func NewLogger(ctx context.Context, cfg LoggerConfig) zerolog.Logger {
rsyslogWriter, err := syslog.Dial(
cfg.RSyslogNetwork, cfg.RSyslogAddress, cfg.SyslogPriority, config.DefaultSyslogTag)
if err != nil {
log.Panic(err)
log.Fatal(err)
}
outputs = append(outputs, zerolog.SyslogLevelWriter(rsyslogWriter))
default:
Expand Down
4 changes: 2 additions & 2 deletions logging/logger_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func NewLogger(ctx context.Context, cfg LoggerConfig) zerolog.Logger {
},
)
case config.Syslog:
log.Panic("Syslog is not supported on Windows")
log.Fatal("Syslog is not supported on Windows")
case config.RSyslog:
log.Panic("RSyslog is not supported on Windows")
log.Fatal("RSyslog is not supported on Windows")
default:
outputs = append(outputs, consoleWriter)
}
Expand Down
5 changes: 2 additions & 3 deletions tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func OTLPTracer(insecure bool, collectorURL, serviceName string) func(context.Co
),
)
if err != nil {
log.Panic(err)
log.Fatal(err)
}

resources, err := resource.New(
Expand All @@ -40,8 +40,7 @@ func OTLPTracer(insecure bool, collectorURL, serviceName string) func(context.Co
),
)
if err != nil {
// logger.Error().Err(err).Msg("Could not set resources")
log.Panic(err)
log.Fatal(err)
}

resources, _ = resource.Merge(
Expand Down