mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
fix: add quality checks to ensure formatted error doesnt remove important info
Signed-off-by: Jesse Simpson <jesse.simpson36@gmail.com>
This commit is contained in:
parent
d8bec4e30f
commit
383a758aec
1 changed files with 28 additions and 1 deletions
|
|
@ -369,6 +369,33 @@ func (t TraceableError) FilterUnnecessaryWords() TraceableError {
|
|||
return t
|
||||
}
|
||||
|
||||
// In the process of formatting the error, we want to ensure that the formatted version of the error
|
||||
// is not losing any necessary information. This function will tokenize and compare the two strings
|
||||
// and if the formatted error doesn't meet the threshold, it will fallback to the originalErr
|
||||
func determineIfFormattedErrorIsAcceptable(formattedErr error, originalErr error) error {
|
||||
formattedErrTokens := strings.Fields(formattedErr.Error())
|
||||
originalErrTokens := strings.Fields(originalErr.Error())
|
||||
|
||||
tokenSet := make(map[string]struct{})
|
||||
for _, token := range originalErrTokens {
|
||||
tokenSet[token] = struct{}{}
|
||||
}
|
||||
|
||||
matchCount := 0
|
||||
for _, token := range formattedErrTokens {
|
||||
if _, exists := tokenSet[token]; exists {
|
||||
matchCount++
|
||||
}
|
||||
}
|
||||
|
||||
equivalenceRating := (float64(matchCount) / float64(len(formattedErrTokens))) * 100
|
||||
fmt.Printf("Rating: %f\n", equivalenceRating)
|
||||
if equivalenceRating >= 80 {
|
||||
return formattedErr
|
||||
}
|
||||
return originalErr
|
||||
}
|
||||
|
||||
func cleanupExecError(filename string, err error) error {
|
||||
if _, isExecError := err.(template.ExecError); !isExecError {
|
||||
return err
|
||||
|
|
@ -442,7 +469,7 @@ func cleanupExecError(filename string, err error) error {
|
|||
return fmt.Errorf("%s", err.Error())
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s", finalErrorString)
|
||||
return determineIfFormattedErrorIsAcceptable(fmt.Errorf("%s", finalErrorString), err)
|
||||
}
|
||||
|
||||
func sortTemplates(tpls map[string]renderable) []string {
|
||||
|
|
|
|||
Loading…
Reference in a new issue