Skip to content

Commit 99b98b1

Browse files
authored
Merge pull request #377 from gatewayd-io/refactor-panics
Don't panic
2 parents 629a1ae + 2e3cac7 commit 99b98b1

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

config/config.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (c *Config) LoadDefaults(ctx context.Context) {
165165
if err != nil {
166166
span.RecordError(err)
167167
span.End()
168-
log.Panic(fmt.Errorf("failed to unmarshal global configuration: %w", err))
168+
log.Fatal(fmt.Errorf("failed to unmarshal global configuration: %w", err))
169169
}
170170

171171
for configObject, configMap := range gconf {
@@ -194,15 +194,15 @@ func (c *Config) LoadDefaults(ctx context.Context) {
194194
err := fmt.Errorf("unknown config object: %s", configObject)
195195
span.RecordError(err)
196196
span.End()
197-
log.Panic(err)
197+
log.Fatal(err)
198198
}
199199
}
200200
}
201201
}
202202
} else if !os.IsNotExist(err) {
203203
span.RecordError(err)
204204
span.End()
205-
log.Panic(fmt.Errorf("failed to read global configuration file: %w", err))
205+
log.Fatal(fmt.Errorf("failed to read global configuration file: %w", err))
206206
}
207207

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

229229
if c.PluginKoanf != nil {
230230
if err := c.PluginKoanf.Load(structs.Provider(c.pluginDefaults, "json"), nil); err != nil {
231231
span.RecordError(err)
232232
span.End()
233-
log.Panic(fmt.Errorf("failed to load default plugin configuration: %w", err))
233+
log.Fatal(fmt.Errorf("failed to load default plugin configuration: %w", err))
234234
}
235235
}
236236

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

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

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

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

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

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

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

341341
if err := c.GlobalKoanf.UnmarshalWithConf("", &c.Global, koanf.UnmarshalConf{
342342
Tag: "json",
343343
}); err != nil {
344344
span.RecordError(err)
345345
span.End()
346-
log.Panic(fmt.Errorf("failed to unmarshal global configuration: %w", err))
346+
log.Fatal(fmt.Errorf("failed to unmarshal global configuration: %w", err))
347347
}
348348

349349
span.End()
@@ -356,7 +356,7 @@ func (c *Config) ValidateGlobalConfig(ctx context.Context) {
356356
if err := c.GlobalKoanf.Unmarshal("", &globalConfig); err != nil {
357357
span.RecordError(err)
358358
span.End()
359-
log.Panic(
359+
log.Fatal(
360360
gerr.ErrValidationFailed.Wrap(
361361
fmt.Errorf("failed to unmarshal global configuration: %w", err)),
362362
)
@@ -466,6 +466,6 @@ func (c *Config) ValidateGlobalConfig(ctx context.Context) {
466466
}
467467
span.RecordError(fmt.Errorf("failed to validate global configuration"))
468468
span.End()
469-
log.Panic("failed to validate global configuration")
469+
log.Fatal("failed to validate global configuration")
470470
}
471471
}

logging/logger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func NewLogger(ctx context.Context, cfg LoggerConfig) zerolog.Logger {
7373
if err != nil {
7474
span.RecordError(err)
7575
span.End()
76-
log.Panic(err)
76+
log.Fatal(err)
7777
}
7878
outputs = append(outputs, syslogWriter)
7979
case config.RSyslog:
@@ -82,7 +82,7 @@ func NewLogger(ctx context.Context, cfg LoggerConfig) zerolog.Logger {
8282
rsyslogWriter, err := syslog.Dial(
8383
cfg.RSyslogNetwork, cfg.RSyslogAddress, cfg.SyslogPriority, config.DefaultSyslogTag)
8484
if err != nil {
85-
log.Panic(err)
85+
log.Fatal(err)
8686
}
8787
outputs = append(outputs, zerolog.SyslogLevelWriter(rsyslogWriter))
8888
default:

logging/logger_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ func NewLogger(ctx context.Context, cfg LoggerConfig) zerolog.Logger {
6868
},
6969
)
7070
case config.Syslog:
71-
log.Panic("Syslog is not supported on Windows")
71+
log.Fatal("Syslog is not supported on Windows")
7272
case config.RSyslog:
73-
log.Panic("RSyslog is not supported on Windows")
73+
log.Fatal("RSyslog is not supported on Windows")
7474
default:
7575
outputs = append(outputs, consoleWriter)
7676
}

tracing/tracing.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func OTLPTracer(insecure bool, collectorURL, serviceName string) func(context.Co
2828
),
2929
)
3030
if err != nil {
31-
log.Panic(err)
31+
log.Fatal(err)
3232
}
3333

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

4746
resources, _ = resource.Merge(

0 commit comments

Comments
 (0)