<commit_before>package host

import (
	"fmt"

	configapi "github.com/openshift/origin/pkg/cmd/server/api"
	configapilatest "github.com/openshift/origin/pkg/cmd/server/api/latest"
	"github.com/openshift/origin/pkg/diagnostics/types"
)

// this would be bad practice if there were ever a need to load more than one master config for diagnostics.
// however we will proceed with the assumption that will never be necessary.
var (
	masterConfigLoaded    = false
	masterConfig          *configapi.MasterConfig
	masterConfigLoadError error
)

func GetMasterConfig(r types.DiagnosticResult, masterConfigFile string) (*configapi.MasterConfig, error) {
	if masterConfigLoaded { // no need to do this more than once
		return masterConfig, masterConfigLoadError
	}
	r.Debug("DH0001", fmt.Sprintf("Looking for master config file at '%s'", masterConfigFile))
	masterConfigLoaded = true
	masterConfig, masterConfigLoadError = configapilatest.ReadAndResolveMasterConfig(masterConfigFile)
	if masterConfigLoadError != nil {
		r.Error("DH0002", masterConfigLoadError, fmt.Sprintf("Could not read master config file '%s':\n(%T) %[2]v", masterConfigFile, masterConfigLoadError))
	} else {
		r.Debug("DH0003", fmt.Sprintf("Found a master config file: %[1]s", masterConfigFile))
	}
	return masterConfig, masterConfigLoadError
}<commit_msg>bug 1419472 print master config error if it exists<commit_after>package host

import (
	"fmt"

	configapi "github.com/openshift/origin/pkg/cmd/server/api"
	configapilatest "github.com/openshift/origin/pkg/cmd/server/api/latest"
	"github.com/openshift/origin/pkg/diagnostics/types"
)

// this would be bad practice if there were ever a need to load more than one master config for diagnostics.
// however we will proceed with the assumption that will never be necessary.
var (
	masterConfigLoaded    = false
	masterConfig          *configapi.MasterConfig
	masterConfigLoadError error
)

func GetMasterConfig(r types.DiagnosticResult, masterConfigFile string) (*configapi.MasterConfig, error) {
	if masterConfigLoaded { // no need to do this more than once
		if masterConfigLoadError != nil {
			printMasterConfigLoadError(r, masterConfigFile)
		}
		return masterConfig, masterConfigLoadError
	}
	r.Debug("DH0001", fmt.Sprintf("Looking for master config file at '%s'", masterConfigFile))
	masterConfigLoaded = true
	masterConfig, masterConfigLoadError = configapilatest.ReadAndResolveMasterConfig(masterConfigFile)
	if masterConfigLoadError != nil {
		printMasterConfigLoadError(r, masterConfigFile)
	} else {
		r.Debug("DH0003", fmt.Sprintf("Found a master config file: %[1]s", masterConfigFile))
	}
	return masterConfig, masterConfigLoadError
}

func printMasterConfigLoadError(r types.DiagnosticResult, masterConfigFile string) {
	r.Error("DH0002", masterConfigLoadError, fmt.Sprintf("Could not read master config file '%s':\n(%T) %[2]v", masterConfigFile, masterConfigLoadError))
}
{'fraction_non_alphanumeric': 0.09513960703205791, 'fraction_numerical': 0.012064805239572561, 'mean_word_length': 5.506726457399103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '898122', 'n_tokens_mistral': 891, 'n_tokens_neox': 842, 'n_words': 238}