Skip to content

Commit

Permalink
chore: replace unstructured root error log, validate configuration fi…
Browse files Browse the repository at this point in the history
…le schema
  • Loading branch information
pandatix committed May 18, 2024
1 parent 2983b39 commit a705b04
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cmd/ctfd-setup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"log"
"os"
"os/signal"
"path/filepath"
Expand Down Expand Up @@ -445,7 +444,7 @@ func main() {
defer stop()

if err := app.RunContext(ctx, os.Args); err != nil {
log.Fatal(err)
ctfdsetup.Log().Error("fatal error", zap.Error(err))
}
}

Expand Down Expand Up @@ -578,11 +577,14 @@ func run(ctx *cli.Context) error {
log.Info("getting configuration file", zap.String("file", f))
if _, err := os.Stat(f); err == nil {
log.Info("configuration file found", zap.String("file", f))
b, err := os.ReadFile(f)
fd, err := os.Open(f)
if err != nil {
return errors.Wrapf(err, "reading file %s", f)
return errors.Wrapf(err, "opening file %s", f)
}
if err := yaml.Unmarshal(b, &conf); err != nil {
defer fd.Close()
dec := yaml.NewDecoder(fd)
dec.KnownFields(true)
if err := dec.Decode(&conf); err != nil {
return errors.Wrap(err, "unmarshalling configuration")
}
}
Expand Down

0 comments on commit a705b04

Please sign in to comment.