wrap errors correctly

This commit is contained in:
2026-07-07 09:34:36 +02:00
parent 24038e36f7
commit 2f77c27715
22 changed files with 95 additions and 94 deletions

View File

@@ -42,7 +42,7 @@ func DocAdd(conf *cfg.Config, jsondoc string) error {
err := json.Unmarshal([]byte(jsondoc), &data)
if err != nil {
return fmt.Errorf("supplied document was not valid JSON: %s", err)
return fmt.Errorf("supplied document was not valid JSON: %w", err)
}
now := fmt.Sprintf("%d", rand.Int64())
@@ -51,7 +51,7 @@ func DocAdd(conf *cfg.Config, jsondoc string) error {
Document(data).
Do(context.Background())
if err != nil {
return fmt.Errorf("failed to create new doc in index %s: %s", conf.Index, esErrorString(err))
return fmt.Errorf("failed to create new doc in index %s: %w", conf.Index, esErrorString(err))
}
fmt.Println(res.Id_)
@@ -63,7 +63,7 @@ func DocShow(conf *cfg.Config, id string) error {
res, err := conf.DefaultCluster.ES().Get(conf.Index, id).
Do(context.Background())
if err != nil {
return fmt.Errorf("failed to retrieve doc in index %s: %s", conf.Index, esErrorString(err))
return fmt.Errorf("failed to retrieve doc in index %s: %w", conf.Index, esErrorString(err))
}
if !res.Found {
@@ -94,7 +94,7 @@ func DocDelete(conf *cfg.Config, queries []string) error {
_, err := conf.DefaultCluster.ES().Delete(conf.Index, id).
Do(context.Background())
if err != nil {
return fmt.Errorf("failed to delete doc in index %s: %s", conf.Index, esErrorString(err))
return fmt.Errorf("failed to delete doc in index %s: %w", conf.Index, esErrorString(err))
}
return nil
@@ -117,7 +117,7 @@ func DocDelete(conf *cfg.Config, queries []string) error {
Request(req).
Do(context.Background())
if err != nil {
return fmt.Errorf("failed to delete docs in index %s: %s", conf.Index, esErrorString(err))
return fmt.Errorf("failed to delete docs in index %s: %w", conf.Index, esErrorString(err))
}
return nil