Skip to content

Commit

Permalink
feat: Improve error messages, when reading insights-client.conf
Browse files Browse the repository at this point in the history
* When it is not possible to read or parse configuration file
  /etc/insights-client/insights-client.conf, then display
  error message containing path to this configuration file
  • Loading branch information
jirihnidek authored and subpop committed Mar 6, 2024
1 parent a1d1d4d commit 6879e6c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func ConfigPath() (string, error) {
return filePath, nil
}

// Get the API server URL based on, insights-client.conf and rhsm.conf
// This URL may differ from prod, stage and Satellite
// GuessAPIURL gets the API server URL based on, insights-client.conf
// and rhsm.conf. This URL may differ from prod, stage and Satellite
func GuessAPIURL() (string, error) {
var uString string
var baseURL *url.URL
Expand All @@ -89,13 +89,14 @@ func GuessAPIURL() (string, error) {
}
var cfg InsightsConf
// Read the config file
data, err := os.ReadFile("/etc/insights-client/insights-client.conf")
confFilePath := "/etc/insights-client/insights-client.conf"
data, err := os.ReadFile(confFilePath)
if err != nil {
return "", fmt.Errorf("fail to read file: %v", err)
return "", fmt.Errorf("failed to read file '%v': %v", confFilePath, err)
}
// Get the config into the struct
if err := ini.UnmarshalWithOptions(data, &cfg, opts); err != nil {
return "", fmt.Errorf("fail to read configuration: %v", err)
return "", fmt.Errorf("failed to parse file '%v': %v", confFilePath, err)
}
APIServer := cfg.InsightsClient.BaseUrl

Expand Down

0 comments on commit 6879e6c

Please sign in to comment.