Skip to content

Commit

Permalink
code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhang committed Dec 5, 2023
1 parent 1d18764 commit 9251d5a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Example:
# Build the package to a archive.
go build -o pkg.a database/sql/driver

mockgen -archive=pkg.a database/sql/driver
mockgen -archive=pkg.a database/sql/driver Conn,Driver
```

### Source mode
Expand Down
3 changes: 1 addition & 2 deletions mockgen/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"go/token"
"go/types"
"log"
"os"

"go.uber.org/mock/mockgen/model"
Expand Down Expand Up @@ -47,7 +46,7 @@ func archiveMode(importPath string, symbols []string, archive string) (*model.Pa
}
it, err := model.InterfaceFromGoTypesType(ti)
if err != nil {
log.Fatal(err)
return nil, err
}
it.Name = m.Name()
pkg.Interfaces = append(pkg.Interfaces, it)
Expand Down
17 changes: 8 additions & 9 deletions mockgen/model/model_gotypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// InterfaceFromGoTypesType returns a pointer to an interface for the
// given reflection interface type.
// given interface type loaded from archive.
func InterfaceFromGoTypesType(it *types.Interface) (*Interface, error) {
intf := &Interface{}

Expand All @@ -23,7 +23,7 @@ func InterfaceFromGoTypesType(it *types.Interface) (*Interface, error) {
var err error
m.In, m.Variadic, m.Out, err = funcArgsFromGoTypesType(mt.Type().(*types.Signature))
if err != nil {
return nil, err
return nil, fmt.Errorf("method %q: %w", mt.Name(), err)
}

intf.AddMethod(m)
Expand All @@ -37,25 +37,24 @@ func funcArgsFromGoTypesType(t *types.Signature) (in []*Parameter, variadic *Par
if t.Variadic() {
nin--
}
var p *Parameter
for i := 0; i < nin; i++ {
p, err = parameterFromGoTypesType(t.Params().At(i), false)
p, err := parameterFromGoTypesType(t.Params().At(i), false)
if err != nil {
return
return nil, nil, nil, err
}
in = append(in, p)
}
if t.Variadic() {
p, err = parameterFromGoTypesType(t.Params().At(nin), true)
p, err := parameterFromGoTypesType(t.Params().At(nin), true)
if err != nil {
return
return nil, nil, nil, err
}
variadic = p
}
for i := 0; i < t.Results().Len(); i++ {
p, err = parameterFromGoTypesType(t.Results().At(i), false)
p, err := parameterFromGoTypesType(t.Results().At(i), false)
if err != nil {
return
return nil, nil, nil, err
}
out = append(out, p)
}
Expand Down

0 comments on commit 9251d5a

Please sign in to comment.