Skip to content

Commit

Permalink
fix: drop pkg/errors
Browse files Browse the repository at this point in the history
  • Loading branch information
morlay committed Oct 12, 2024
1 parent cafe221 commit 5253b77
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 26 deletions.
5 changes: 2 additions & 3 deletions devpkg/partialstruct/partialstruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/octohelm/gengo/devpkg/deepcopygen/helper"

"github.com/octohelm/gengo/pkg/gengo"
"github.com/pkg/errors"
)

func init() {
Expand Down Expand Up @@ -56,7 +55,7 @@ func (g *partialStructGen) GenerateType(c gengo.Context, named *types.Named) err

ts, ok := underlying.(*types.Struct)
if !ok {
return errors.Errorf("must be struct type, but got %s", underlying)
return fmt.Errorf("must be struct type, but got %s", underlying)
}

pkg := c.Package(named.Obj().Pkg().Path())
Expand Down Expand Up @@ -84,7 +83,7 @@ func (g *partialStructGen) GenerateType(c gengo.Context, named *types.Named) err
}

if ps.Origin == nil {
return errors.Errorf("need to define type like `type xxx sourcepkg.Type`")
return fmt.Errorf("need to define type like `type xxx sourcepkg.Type`")
}

return ps.generate(c, named, ts)
Expand Down
4 changes: 2 additions & 2 deletions devpkg/runtimedocgen/runtimedoc.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package runtimedocgen

import (
"fmt"
"go/ast"
"go/types"

"github.com/octohelm/gengo/pkg/gengo"
"github.com/pkg/errors"
)

func init() {
Expand Down Expand Up @@ -110,7 +110,7 @@ func(v @Type) RuntimeDoc(names ...string) ([]string, bool) {
_, fieldDoc := c.Doc(f)

if _, ok := f.Type().(*types.Struct); ok {
c.Logger().Warn(errors.Errorf("skip inline struct in %s", named))
c.Logger().Warn(fmt.Errorf("skip inline struct in %s", named))
continue
}

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/go-courier/logr v0.3.0
github.com/octohelm/x v0.0.0-20240904081416-42a1ee2d28a9
github.com/onsi/gomega v1.34.2
github.com/pkg/errors v0.9.1
golang.org/x/sync v0.8.0
golang.org/x/text v0.18.0
golang.org/x/tools v0.25.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo
github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI=
github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8=
github.com/onsi/gomega v1.34.2/go.mod h1:v1xfxRgk0KIsG+QOdm7p8UosrOzPYRo60fd3B/1Dukc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
Expand Down
12 changes: 6 additions & 6 deletions pkg/gengo/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package gengo

import (
corecontext "context"
"errors"
"fmt"
"go/token"
"go/types"
"log/slog"
Expand All @@ -10,12 +12,10 @@ import (
"strings"
"sync"

reflectx "github.com/octohelm/x/reflect"
"golang.org/x/sync/errgroup"

"github.com/go-courier/logr"
gengotypes "github.com/octohelm/gengo/pkg/types"
"github.com/pkg/errors"
reflectx "github.com/octohelm/x/reflect"
"golang.org/x/sync/errgroup"
)

type Executor interface {
Expand Down Expand Up @@ -86,7 +86,7 @@ func (c *context) pkgExecute(ctx corecontext.Context, pkg string, generators ...

p, ok := c.universe[pkg]
if !ok {
return errors.Errorf("invalid pkg `%s`", pkg)
return fmt.Errorf("invalid pkg `%s`", pkg)
}

pkgCtx := &context{
Expand Down Expand Up @@ -128,7 +128,7 @@ func (c *context) pkgExecute(ctx corecontext.Context, pkg string, generators ...
pkgCtxForGen.l = logr.FromContext(ctx).WithValues("gengo", g.Name())

if e := pkgCtxForGen.doGenerate(ctx, g); e != nil {
return errors.Wrapf(e, "`%s` generate failed for %s", g.Name(), pkgCtx.pkg.Pkg().Path())
return fmt.Errorf("`%s` generate failed for %s: %w", g.Name(), pkgCtx.pkg.Pkg().Path(), e)
}

gfs.Store(g.Name(), pkgCtxForGen.genfile)
Expand Down
3 changes: 2 additions & 1 deletion pkg/gengo/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package gengo

import (
"bytes"
testingx "github.com/octohelm/x/testing"
"reflect"
"testing"

testingx "github.com/octohelm/x/testing"

"github.com/octohelm/gengo/pkg/namer"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/gengo/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gengo
import (
"go/types"

"github.com/pkg/errors"
"errors"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions pkg/gengo/id_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package gengo_test

import (
"reflect"
"testing"

"github.com/octohelm/gengo/pkg/gengo"
gengotypes "github.com/octohelm/gengo/pkg/types"
testingx "github.com/octohelm/x/testing"
"reflect"
"testing"
)

type List[T any] struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/namer/__generators__/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package main
import (
"bytes"
"fmt"
"golang.org/x/tools/go/packages"
"os"
"slices"
"strings"

"golang.org/x/tools/go/packages"
)

func main() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/namer/namer.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package namer

import (
gengotypes "github.com/octohelm/gengo/pkg/types"
"go/types"
"strings"

gengotypes "github.com/octohelm/gengo/pkg/types"
)

type Namer interface {
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestLoad(t *testing.T) {
"FuncWillCall": `(2, github.com/octohelm/gengo/testdata/a.String)`,
"FuncReturnWithCallDirectly": `(2, github.com/octohelm/gengo/testdata/a.String)`,
"FuncWithNamedReturn": `(2, github.com/octohelm/gengo/testdata/a.String)`,
"FuncSingleNamedReturnByAssign": `("1", "2", *github.com/pkg/errors.fundamental)`,
"FuncSingleNamedReturnByAssign": `("1", "2", *errors.errorString)`,
"FunWithSwitch": `("a1" | "a2" | "a3", "b1" | "b2" | "b3")`,
"FuncWithIf": `("a0" | "a1" | string)`,
"FuncCallReturnAssign": `(2, github.com/octohelm/gengo/testdata/a.String)`,
Expand Down
3 changes: 1 addition & 2 deletions pkg/types/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types

import (
"fmt"
"github.com/pkg/errors"
"go/ast"
"go/types"
"strings"
Expand Down Expand Up @@ -109,7 +108,7 @@ func ParseTypeRef(s string) (*TypeRef, error) {
return t, nil
}

return nil, errors.Errorf("invalid type ref: %s", s)
return nil, fmt.Errorf("invalid type ref: %s", s)
}

if i := strings.LastIndex(s, "."); i > 0 {
Expand Down
2 changes: 1 addition & 1 deletion testdata/a/b/zz_generated.defaulter.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Package b GENERATED BY gengo:defaulter
Package b GENERATED BY gengo:defaulter
DON'T EDIT THIS FILE
*/
package b
Expand Down
2 changes: 1 addition & 1 deletion testdata/a/b/zz_generated.runtimedoc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Package b GENERATED BY gengo:runtimedoc
Package b GENERATED BY gengo:runtimedoc
DON'T EDIT THIS FILE
*/
package b
Expand Down
2 changes: 1 addition & 1 deletion testdata/a/function_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package a
import (
"strings"

"github.com/pkg/errors"
"errors"

"github.com/octohelm/gengo/testdata/a/b"
)
Expand Down

0 comments on commit 5253b77

Please sign in to comment.