cleanup: wrap errors using go 1.13 built-ins
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
81389b3cb9
commit
9e86b011d5
@ -2,13 +2,13 @@ package dagger
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
cueerrors "cuelang.org/go/cue/errors"
|
cueerrors "cuelang.org/go/cue/errors"
|
||||||
cueload "cuelang.org/go/cue/load"
|
cueload "cuelang.org/go/cue/load"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
"dagger.cloud/go/dagger/compiler"
|
"dagger.cloud/go/dagger/compiler"
|
||||||
|
@ -3,12 +3,12 @@ package dagger
|
|||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
@ -45,7 +45,7 @@ func NewClient(ctx context.Context, host string) (*Client, error) {
|
|||||||
}
|
}
|
||||||
c, err := bk.New(ctx, host)
|
c, err := bk.New(ctx, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "buildkit client")
|
return nil, fmt.Errorf("buildkit client: %w", err)
|
||||||
}
|
}
|
||||||
return &Client{
|
return &Client{
|
||||||
c: c,
|
c: c,
|
||||||
@ -143,7 +143,7 @@ func (c *Client) buildfn(ctx context.Context, env *Env, ch chan *bk.SolveStatus,
|
|||||||
return outdir.Result(ctx)
|
return outdir.Result(ctx)
|
||||||
}, ch)
|
}, ch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(bkCleanError(err), "buildkit solve")
|
return fmt.Errorf("buildkit solve: %w", bkCleanError(err))
|
||||||
}
|
}
|
||||||
for k, v := range resp.ExporterResponse {
|
for k, v := range resp.ExporterResponse {
|
||||||
// FIXME consume exporter response
|
// FIXME consume exporter response
|
||||||
@ -173,7 +173,7 @@ func (c *Client) outputfn(ctx context.Context, r io.Reader) (*compiler.Value, er
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "read tar stream")
|
return nil, fmt.Errorf("read tar stream: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
lg := lg.
|
lg := lg.
|
||||||
@ -192,7 +192,7 @@ func (c *Client) outputfn(ctx context.Context, r io.Reader) (*compiler.Value, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := out.Fill(v); err != nil {
|
if err := out.Fill(v); err != nil {
|
||||||
return nil, errors.Wrap(err, h.Name)
|
return nil, fmt.Errorf("%s: %w", h.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
|
@ -2,10 +2,10 @@ package dagger
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"cuelang.org/go/cue"
|
"cuelang.org/go/cue"
|
||||||
cueflow "cuelang.org/go/tools/flow"
|
cueflow "cuelang.org/go/tools/flow"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
"dagger.cloud/go/dagger/compiler"
|
"dagger.cloud/go/dagger/compiler"
|
||||||
@ -102,7 +102,7 @@ func (env *Env) Update(ctx context.Context, s Solver) error {
|
|||||||
// FIXME: BuildAll() to force all files (no required package..)
|
// FIXME: BuildAll() to force all files (no required package..)
|
||||||
base, err := CueBuild(ctx, p.FS())
|
base, err := CueBuild(ctx, p.FS())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "base config")
|
return fmt.Errorf("base config: %w", err)
|
||||||
}
|
}
|
||||||
// Commit
|
// Commit
|
||||||
return env.set(
|
return env.set(
|
||||||
@ -176,15 +176,15 @@ func (env *Env) set(base, input, output *compiler.Value) (err error) {
|
|||||||
|
|
||||||
stateInst, err = stateInst.Fill(base.Cue())
|
stateInst, err = stateInst.Fill(base.Cue())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "merge base & input")
|
return fmt.Errorf("merge base & input: %w", err)
|
||||||
}
|
}
|
||||||
stateInst, err = stateInst.Fill(input.Cue())
|
stateInst, err = stateInst.Fill(input.Cue())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "merge base & input")
|
return fmt.Errorf("merge base & input: %w", err)
|
||||||
}
|
}
|
||||||
stateInst, err = stateInst.Fill(output.Cue())
|
stateInst, err = stateInst.Fill(output.Cue())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "merge output with base & input")
|
return fmt.Errorf("merge output with base & input: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
state := compiler.Wrap(stateInst.Value(), stateInst)
|
state := compiler.Wrap(stateInst.Value(), stateInst)
|
||||||
|
@ -2,13 +2,13 @@ package dagger
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/moby/buildkit/client/llb"
|
"github.com/moby/buildkit/client/llb"
|
||||||
bkgw "github.com/moby/buildkit/frontend/gateway/client"
|
bkgw "github.com/moby/buildkit/frontend/gateway/client"
|
||||||
"github.com/pkg/errors"
|
|
||||||
fstypes "github.com/tonistiigi/fsutil/types"
|
fstypes "github.com/tonistiigi/fsutil/types"
|
||||||
|
|
||||||
"dagger.cloud/go/dagger/compiler"
|
"dagger.cloud/go/dagger/compiler"
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/moby/buildkit/client/llb"
|
"github.com/moby/buildkit/client/llb"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
@ -349,7 +348,7 @@ func (p *Pipeline) Export(ctx context.Context, op *compiler.Value) error {
|
|||||||
}
|
}
|
||||||
contents, err := p.fs.ReadFile(ctx, source)
|
contents, err := p.fs.ReadFile(ctx, source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "export %s", source)
|
return fmt.Errorf("export %s: %w", source, err)
|
||||||
}
|
}
|
||||||
switch format {
|
switch format {
|
||||||
case "string":
|
case "string":
|
||||||
|
@ -3,12 +3,12 @@ package dagger
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/moby/buildkit/client/llb"
|
"github.com/moby/buildkit/client/llb"
|
||||||
bkgw "github.com/moby/buildkit/frontend/gateway/client"
|
bkgw "github.com/moby/buildkit/frontend/gateway/client"
|
||||||
"github.com/moby/buildkit/solver/pb"
|
"github.com/moby/buildkit/solver/pb"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ func dumpLLB(def *llb.Definition) ([]byte, error) {
|
|||||||
for _, dt := range def.Def {
|
for _, dt := range def.Def {
|
||||||
var op pb.Op
|
var op pb.Op
|
||||||
if err := (&op).Unmarshal(dt); err != nil {
|
if err := (&op).Unmarshal(dt); err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to parse op")
|
return nil, fmt.Errorf("failed to parse op: %w", err)
|
||||||
}
|
}
|
||||||
dgst := digest.FromBytes(dt)
|
dgst := digest.FromBytes(dt)
|
||||||
ent := llbOp{Op: op, Digest: dgst, OpMetadata: def.Metadata[dgst]}
|
ent := llbOp{Op: op, Digest: dgst, OpMetadata: def.Metadata[dgst]}
|
||||||
|
1
go.mod
1
go.mod
@ -9,7 +9,6 @@ require (
|
|||||||
github.com/emicklei/proto v1.9.0 // indirect
|
github.com/emicklei/proto v1.9.0 // indirect
|
||||||
github.com/moby/buildkit v0.8.1
|
github.com/moby/buildkit v0.8.1
|
||||||
github.com/opencontainers/go-digest v1.0.0
|
github.com/opencontainers/go-digest v1.0.0
|
||||||
github.com/pkg/errors v0.9.1
|
|
||||||
github.com/rs/zerolog v1.20.0
|
github.com/rs/zerolog v1.20.0
|
||||||
github.com/spf13/cobra v1.0.0
|
github.com/spf13/cobra v1.0.0
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
|
Reference in New Issue
Block a user