Skip to content

Commit

Permalink
Merge pull request #1005 from jonjohnsonjr/misleading-err
Browse files Browse the repository at this point in the history
Return better error messages for missing config
  • Loading branch information
jonjohnsonjr committed Jan 5, 2024
2 parents 914648f + f55a918 commit 2d813ed
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions pkg/build/types/image_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,31 @@ func (ic *ImageConfiguration) parse(configData []byte, logger log.Logger) error
return nil
}

// Loads an image configuration given a configuration file path.
func (ic *ImageConfiguration) Load(imageConfigPath string, logger log.Logger) error {
data, err := os.ReadFile(imageConfigPath)
if err == nil {
return ic.parse(data, logger)
func (ic *ImageConfiguration) maybeLoadRemote(imageConfigPath string, logger log.Logger) error {
data, err := fetch.Fetch(imageConfigPath)
if err != nil {
return fmt.Errorf("unable to fetch remote include from git: %w", err)
}

// At this point, we're doing a remote config file.
logger.Warnf("remote configurations are an experimental feature and subject to change.")
return ic.parse(data, logger)
}

data, err = fetch.Fetch(imageConfigPath)
// Loads an image configuration given a configuration file path.
func (ic *ImageConfiguration) Load(imageConfigPath string, logger log.Logger) error {
data, err := os.ReadFile(imageConfigPath)
if err != nil {
return fmt.Errorf("unable to fetch remote include from git: %w", err)
logger.Warnf("loading config file failed: %v", err)
logger.Warnf("attempting to load remote configuration")
logger.Warnf("NOTE: remote configurations are an experimental feature and subject to change.")

if err := ic.maybeLoadRemote(imageConfigPath, logger); err == nil {
return nil
} else {
// At this point, we're doing a remote config file.
logger.Warnf("loading remote configuration failed: %v", err)
}

return err
}

return ic.parse(data, logger)
Expand Down

0 comments on commit 2d813ed

Please sign in to comment.