internal/gofix and fix error wrapping (#76)

This commit is contained in:
T. von Dein
2026-07-07 10:41:34 +02:00
parent f10366dbde
commit b8e0ee074c
28 changed files with 109 additions and 119 deletions

View File

@@ -17,29 +17,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package es
import (
"errors"
"fmt"
"strings"
"github.com/elastic/go-elasticsearch/v9/typedapi/types"
)
func esErrorString(err error) string {
func esErrorString(err error) error {
msg := err.Error()
switch e := err.(type) {
case *types.ElasticsearchError:
causes := ""
var causes strings.Builder
for _, cause := range e.ErrorCause.RootCause {
causes += fmt.Sprintf("%s\n", *cause.Reason)
// FIXME: re-activate linter here, see https://github.com/golangci/golangci-lint/issues/6662
//nolint:staticcheck
causes.WriteString(fmt.Sprintf("%s\n", *cause.Reason))
}
if e.ErrorCause.Reason != nil {
msg = *e.ErrorCause.Reason + ": " + causes
msg = *e.ErrorCause.Reason + ": " + causes.String()
} else {
msg = fmt.Sprintf("http status %d: ", e.Status)
}
}
return msg
return errors.New(msg)
}