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

Return better error messages for missing config #1005

Merged
merged 1 commit into from
Jan 5, 2024
Merged
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
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
Loading