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

fix: error on no scaffold rc and empty file #91

Merged
merged 3 commits into from
Dec 25, 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
5 changes: 5 additions & 0 deletions app/scaffold/rc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scaffold

import (
"errors"
"fmt"
"io"
"net/url"
Expand Down Expand Up @@ -52,6 +53,10 @@ func NewScaffoldRC(r io.Reader) (*ScaffoldRC, error) {

err := yaml.NewDecoder(r).Decode(&out)
if err != nil {
if errors.Is(err, io.EOF) {
// Asssume empty file and return empty struct
return &out, nil
}
return nil, err
}

Expand Down
27 changes: 16 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,25 @@ func main() {
// Parse scaffoldrc file
scaffoldrcFile, err := os.Open(ctrl.Flags.ScaffoldRCPath)
if err != nil {
return fmt.Errorf("failed to open scaffoldrc file: %w", err)
if !errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("failed to open scaffoldrc file: %w", err)
}
log.Debug().Msg("scaffoldrc file does not exist, skipping")
}

rc, err := scaffold.NewScaffoldRC(scaffoldrcFile)
if err != nil {
switch {
case errors.As(err, &scaffold.RcValidationErrors{}):
// I _know_ this is a valid cast, but the linter doesn't
e := err.(scaffold.RcValidationErrors) //nolint:errorlint
for _, err := range e {
log.Error().Str("key", err.Key).Msg(err.Cause.Error())
rc := &scaffold.ScaffoldRC{}
if scaffoldrcFile != nil {
rc, err = scaffold.NewScaffoldRC(scaffoldrcFile)
if err != nil {
scaferrs := scaffold.RcValidationErrors{}
switch {
case errors.As(err, &scaferrs):
for _, err := range scaferrs {
log.Error().Str("key", err.Key).Msg(err.Cause.Error())
}
default:
return fmt.Errorf("failed to parse scaffoldrc file: %w", err)
}
default:
return fmt.Errorf("failed to parse scaffoldrc file: %w", err)
}
}

Expand Down
Loading