Skip to content

Commit

Permalink
chore: improve filesystem related error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pandatix committed Jun 1, 2024
1 parent 4f3be20 commit 16b9518
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
26 changes: 12 additions & 14 deletions cmd/ctfd-setup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,21 +574,19 @@ func run(ctx *cli.Context) error {
}

// Read and unmarshal setup config file if any
if ctx.IsSet("file") && ctx.String("file") != "" {
f := ctx.String("file")
log.Info("getting configuration file", zap.String("file", f))
if _, err := os.Stat(f); err == nil {
fd, err := os.Open(f)
if err != nil {
return errors.Wrapf(err, "opening file %s", f)
}
defer fd.Close()
if f := ctx.String("file"); f != "" {
log.Info("loading configuration file", zap.String("file", f))

dec := yaml.NewDecoder(fd)
dec.KnownFields(true)
if err := dec.Decode(&conf); err != nil {
return errors.Wrap(err, "unmarshalling configuration")
}
fd, err := os.Open(f)
if err != nil {
return errors.Wrapf(err, "opening file %s", f)
}
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
8 changes: 4 additions & 4 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ func updateSetup(ctx context.Context, client *api.Client, conf *Config) error {
},
}, api.WithContext(ctx))
if err != nil {
return err
return errors.Wrap(err, "pushing theme logo")
}
if _, err := client.PatchConfigsCTFLogo(&api.PatchConfigsCTFLogo{
Value: &lf[0].Location,
}, api.WithContext(ctx)); err != nil {
return err
return errors.Wrap(err, "patching CTF logo")
}
}

Expand All @@ -103,12 +103,12 @@ func updateSetup(ctx context.Context, client *api.Client, conf *Config) error {
},
}, api.WithContext(ctx))
if err != nil {
return err
return errors.Wrap(err, "pushing theme small icon")
}
if _, err := client.PatchConfigsCTFSmallIcon(&api.PatchConfigsCTFLogo{
Value: &smf[0].Location,
}, api.WithContext(ctx)); err != nil {
return err
return errors.Wrap(err, "patching CTF small icon")
}
}

Expand Down

0 comments on commit 16b9518

Please sign in to comment.