Skip to content

Commit

Permalink
Merge pull request #714 from homeport/remove/wrap-import
Browse files Browse the repository at this point in the history
Remove `wrap` import
  • Loading branch information
HeavyWombat authored Jan 12, 2025
2 parents 08c0de8 + 207ede2 commit 3e8efba
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
11 changes: 6 additions & 5 deletions internal/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,27 @@
package cmd

import (
"errors"
"fmt"
"os"

"github.com/gonvenience/wrap"
"github.com/mattn/go-isatty"
)

func combineErrorsFromChannel(context string, c chan error) error {
var errors []error
var errs []error
for err := range c {
if err != nil {
errors = append(errors, err)
errs = append(errs, err)
}
}

switch len(errors) {
switch len(errs) {
case 0:
return nil

default:
return wrap.Errors(errors, context)
return fmt.Errorf("%s: %w", context, errors.Join(errs...))
}
}

Expand Down
5 changes: 0 additions & 5 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/gonvenience/bunt"
"github.com/gonvenience/neat"
"github.com/gonvenience/term"
"github.com/gonvenience/wrap"
)

type wrappedError interface {
Expand Down Expand Up @@ -89,10 +88,6 @@ func Execute() {
var headline, content string

switch err := err.(type) {
case wrap.ContextError:
headline = bunt.Sprintf("*Error:* _%s_", err.Context())
content = err.Cause().Error()

case wrappedError:
headline = title(err)
content = cause(err)
Expand Down
20 changes: 10 additions & 10 deletions pkg/havener/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"archive/tar"
"bytes"
"compress/gzip"
"errors"
"fmt"
"io"
"os"
Expand All @@ -33,7 +34,6 @@ import (
"strings"
"sync"

"github.com/gonvenience/wrap"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/printers"
Expand Down Expand Up @@ -104,7 +104,7 @@ func (h *Hvnr) RetrieveLogs(parallelDownloads int, target string, includeConfigF
}

tasks := make(chan *task)
errors := []error{}
errs := []error{}

var wg sync.WaitGroup
wg.Add(parallelDownloads)
Expand All @@ -121,7 +121,7 @@ func (h *Hvnr) RetrieveLogs(parallelDownloads int, target string, includeConfigF
}

if err != nil {
errors = append(errors, err)
errs = append(errs, err)
}
}

Expand All @@ -133,24 +133,24 @@ func (h *Hvnr) RetrieveLogs(parallelDownloads int, target string, includeConfigF
}

if err != nil {
errors = append(errors, err)
errs = append(errs, err)
}
}

case "container-logs":
errors = append(
errors,
errs = append(
errs,
h.retrieveContainerLogs(task.pod, task.baseDir)...,
)

case "describe-pods":
if err := h.writeDescribePodToDisk(task.pod, task.baseDir); err != nil {
errors = append(errors, err)
errs = append(errs, err)
}

case "store-yaml":
if err := h.saveDeploymentYAML(task.pod, task.baseDir); err != nil {
errors = append(errors, err)
errs = append(errs, err)
}
}
}
Expand Down Expand Up @@ -225,8 +225,8 @@ func (h *Hvnr) RetrieveLogs(parallelDownloads int, target string, includeConfigF
close(tasks)
wg.Wait()

if len(errors) > 0 {
return wrap.Errors(errors, "failed to retrieve logs from cluster")
if len(errs) > 0 {
return fmt.Errorf("failed to retrieve logs from cluster: %w", errors.Join(errs...))
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions pkg/havener/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package havener
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
Expand All @@ -32,7 +33,6 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/gonvenience/wrap"
"k8s.io/apimachinery/pkg/api/resource"
)

Expand Down Expand Up @@ -261,13 +261,13 @@ func (h *Hvnr) TopDetails() (*TopDetails, error) {
wg.Wait()
close(errChan)

errors := []error{}
var errs []error
for err := range errChan {
errors = append(errors, err)
errs = append(errs, err)
}

if len(errors) > 0 {
return nil, wrap.Errors(errors, "failed to retrieve usage details from cluster")
if len(errs) > 0 {
return nil, fmt.Errorf("failed to retrieve usage details from cluster: %w", errors.Join(errs...))
}

return &result, nil
Expand Down

0 comments on commit 3e8efba

Please sign in to comment.