Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed all lint errcheck in number of TLDs #2978

Merged
merged 2 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions client/rpcflags/rpcflags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func TestNewClientDialOptionsFromFlagsWithTLSCertFileNotSet(t *testing.T) {
if err != nil {
t.Errorf("failed to dial %v: %v", logEnv.Address, err)
}
defer conn.Close()
defer func() {
if err := conn.Close(); err != nil {
t.Error(err)
}
}()

adminClient := trillian.NewTrillianAdminClient(conn)
if _, err = adminClient.ListTrees(context.Background(), &trillian.ListTreesRequest{}); err != nil {
Expand Down Expand Up @@ -127,7 +131,11 @@ func TestNewClientDialOptionsFromFlagsWithTLSCertFileSet(t *testing.T) {
if err != nil {
t.Errorf("failed to dial %v: %v", logEnv.Address, err)
}
defer conn.Close()
defer func() {
if err := conn.Close(); err != nil {
t.Error(err)
}
}()

adminClient := trillian.NewTrillianAdminClient(conn)
if _, err := adminClient.ListTrees(context.Background(), &trillian.ListTreesRequest{}); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion cmd/createtree/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ func createTree(ctx context.Context) (*trillian.Tree, error) {
if err != nil {
return nil, fmt.Errorf("failed to dial %v: %v", *adminServerAddr, err)
}
defer conn.Close()
defer func() {
if err := conn.Close(); err != nil {
klog.Errorf("Close(): %v", err)
}
}()

adminClient := trillian.NewTrillianAdminClient(conn)
logClient := trillian.NewTrillianLogClient(conn)
Expand Down
6 changes: 5 additions & 1 deletion cmd/deletetree/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ func main() {
if err != nil {
klog.Exitf("Failed to dial %v: %v", *adminServerAddr, err)
}
defer conn.Close()
defer func() {
if err := conn.Close(); err != nil {
klog.Errorf("Close(): %v", err)
}
}()

a := trillian.NewTrillianAdminClient(conn)
if !*undeleteTree {
Expand Down
26 changes: 20 additions & 6 deletions cmd/internal/serverutil/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ func (m *Main) healthz(rw http.ResponseWriter, req *http.Request) {
defer cancel()
if err := m.IsHealthy(ctx); err != nil {
rw.WriteHeader(http.StatusServiceUnavailable)
rw.Write([]byte(err.Error()))
if _, err := rw.Write([]byte(err.Error())); err != nil {
klog.Errorf("Write(): %v", err)
}
return
}
}
rw.Write([]byte("ok"))
if _, err := rw.Write([]byte("ok")); err != nil {
klog.Errorf("Write(): %v", err)
}
}

// Run starts the configured server. Blocks until the server exits.
Expand All @@ -119,7 +123,11 @@ func (m *Main) Run(ctx context.Context) error {
}
defer srv.GracefulStop()

defer m.DBClose()
defer func() {
if err := m.DBClose(); err != nil {
klog.Errorf("DBClose(): %v", err)
}
}()

if err := m.RegisterServerFn(srv, m.Registry); err != nil {
return err
Expand Down Expand Up @@ -278,15 +286,21 @@ func AnnounceSelf(ctx context.Context, client *clientv3.Client, etcdService, end
klog.Exitf("Failed to create etcd manager: %v", err)
}
fullEndpoint := fmt.Sprintf("%s/%s", etcdService, endpoint)
em.AddEndpoint(ctx, fullEndpoint, endpoints.Endpoint{Addr: endpoint})
if err := em.AddEndpoint(ctx, fullEndpoint, endpoints.Endpoint{Addr: endpoint}); err != nil {
klog.Exitf("Failed to add endpoint: %v", err)
}
klog.Infof("Announcing our presence in %v", etcdService)

return func() {
// Use a background context because the original context may have been cancelled.
klog.Infof("Removing our presence in %v", etcdService)
ctx := context.Background()
em.DeleteEndpoint(ctx, fullEndpoint)
client.Revoke(ctx, leaseRsp.ID)
if err := em.DeleteEndpoint(ctx, fullEndpoint); err != nil {
klog.Exitf("Failed to delete endpoint: %v", err)
}
if _, err := client.Revoke(ctx, leaseRsp.ID); err != nil {
klog.Exitf("Failed to revoke lease: %v", err)
}
}
}

Expand Down
20 changes: 16 additions & 4 deletions cmd/trillian_log_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ func main() {
if err != nil {
klog.Exitf("Failed to get storage provider: %v", err)
}
defer sp.Close()
defer func() {
if err := sp.Close(); err != nil {
klog.Errorf("Close(): %v", err)
}
}()

var client *clientv3.Client
if servers := *etcd.Servers; servers != "" {
Expand All @@ -127,7 +131,11 @@ func main() {
}); err != nil {
klog.Exitf("Failed to connect to etcd at %v: %v", servers, err)
}
defer client.Close()
defer func() {
if err := client.Close(); err != nil {
klog.Errorf("Close(): %v", err)
}
}()
}

// Announce our endpoints to etcd if so configured.
Expand All @@ -154,7 +162,9 @@ func main() {
// Enable CPU profile if requested.
if *cpuProfile != "" {
f := mustCreate(*cpuProfile)
pprof.StartCPUProfile(f)
if err := pprof.StartCPUProfile(f); err != nil {
klog.Exitf("StartCPUProfile(): %v", err)
}
defer pprof.StopCPUProfile()
}

Expand Down Expand Up @@ -196,7 +206,9 @@ func main() {

if *memProfile != "" {
f := mustCreate(*memProfile)
pprof.WriteHeapProfile(f)
if err := pprof.WriteHeapProfile(f); err != nil {
klog.Exitf("WriteHeapProfile(): %v", err)
}
}
}

Expand Down
20 changes: 16 additions & 4 deletions cmd/trillian_log_signer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ func main() {
if err != nil {
klog.Exitf("Failed to get storage provider: %v", err)
}
defer sp.Close()
defer func() {
if err := sp.Close(); err != nil {
klog.Errorf("Close(): %v", err)
}
}()

var client *clientv3.Client
if servers := *etcd.Servers; servers != "" {
Expand All @@ -124,7 +128,11 @@ func main() {
}); err != nil {
klog.Exitf("Failed to connect to etcd at %v: %v", servers, err)
}
defer client.Close()
defer func() {
if err := client.Close(); err != nil {
klog.Errorf("Close(): %v", err)
}
}()
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -188,7 +196,9 @@ func main() {
// Enable CPU profile if requested
if *cpuProfile != "" {
f := mustCreate(*cpuProfile)
pprof.StartCPUProfile(f)
if err := pprof.StartCPUProfile(f); err != nil {
klog.Exitf("StartCPUProfile(): %v", err)
}
defer pprof.StopCPUProfile()
}

Expand All @@ -211,7 +221,9 @@ func main() {

if *memProfile != "" {
f := mustCreate(*memProfile)
pprof.WriteHeapProfile(f)
if err := pprof.WriteHeapProfile(f); err != nil {
klog.Exitf("WriteHeapProfile(): %v", err)
}
}

// Give things a few seconds to tidy up
Expand Down
6 changes: 5 additions & 1 deletion cmd/updatetree/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ func updateTree(ctx context.Context) (*trillian.Tree, error) {
if err != nil {
return nil, fmt.Errorf("failed to dial %v: %v", *adminServerAddr, err)
}
defer conn.Close()
defer func() {
if err := conn.Close(); err != nil {
klog.Errorf("Close(): %v", err)
}
}()

client := trillian.NewTrillianAdminClient(conn)
for {
Expand Down
7 changes: 6 additions & 1 deletion experimental/batchmap/cmd/build/mapdemo.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ func (fn *writeTileFn) ProcessElement(ctx context.Context, t *batchmap.Tile) err
if err != nil {
return err
}
defer w.Close()

defer func() {
if err := w.Close(); err != nil {
klog.Errorf("Close(): %v", err)
}
}()

bs, err := json.Marshal(t)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion integration/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/transparency-dev/merkle/rfc6962"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/types/known/durationpb"
"k8s.io/klog/v2"
)

func run(treeSize, batchSize int, leafFormat string) (string, error) {
Expand Down Expand Up @@ -171,7 +172,10 @@ func latestRevisions(ls storage.LogStorage, treeID int64, hasher merkle.LogHashe
out := new(bytes.Buffer)
for _, k := range keys {
subtree := vMap[k].subtree
cache.PopulateLogTile(subtree, hasher)
if err := cache.PopulateLogTile(subtree, hasher); err != nil {
// TODO(mhutchinson): This error should be propagated.
klog.Errorf("PopulateLogTile(): %v", err)
}
fmt.Fprintf(out, "%s\n", prototext.Format(subtree))
}
return out.String(), nil
Expand Down
6 changes: 5 additions & 1 deletion integration/log_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ func TestLiveLogIntegration(t *testing.T) {
if err != nil {
t.Fatalf("Failed to connect to log server: %v", err)
}
defer conn.Close()
defer func() {
if err := conn.Close(); err != nil {
t.Errorf("Close(): %v", err)
}
}()

lc := trillian.NewTrillianLogClient(conn)
if err := RunLogIntegration(lc, params); err != nil {
Expand Down
9 changes: 6 additions & 3 deletions integration/quota/quota_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/status"
"k8s.io/klog/v2"

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
)
Expand Down Expand Up @@ -206,18 +207,20 @@ type testServer struct {

func (s *testServer) close() {
if s.conn != nil {
s.conn.Close()
_ = s.conn.Close()
}
if s.server != nil {
s.server.GracefulStop()
}
if s.lis != nil {
s.lis.Close()
_ = s.lis.Close()
}
}

func (s *testServer) serve() {
s.server.Serve(s.lis)
if err := s.server.Serve(s.lis); err != nil {
klog.Errorf("Serve(): %v", err)
}
}

// newTestServer returns a new testServer configured for integration tests.
Expand Down
12 changes: 10 additions & 2 deletions integration/storagetest/logtests.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,23 @@ func (*logTests) TestSnapshot(ctx context.Context, t *testing.T, s storage.LogSt
tx, err := s.SnapshotForTree(ctx, test.tree)

if err == storage.ErrTreeNeedsInit {
defer tx.Close()
defer func() {
if err := tx.Close(); err != nil {
t.Errorf("Close(): %v", err)
}
}()
}

if hasErr := err != nil; hasErr != test.wantErr {
t.Fatalf("err: %v, wantErr = %v", err, test.wantErr)
} else if hasErr {
return
}
defer tx.Close()
defer func() {
if err := tx.Close(); err != nil {
t.Errorf("Close(): %v", err)
}
}()

_, err = tx.LatestSignedLogRoot(ctx)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions log/operation_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,18 @@ func TestMasterFor(t *testing.T) {
lom := NewOperationManager(info, nil)

// Check mastership twice, to give the election threads a chance to get started and report.
lom.masterFor(testCtx, firstIDs)
if _, err := lom.masterFor(testCtx, firstIDs); err != nil {
t.Error(err)
}
time.Sleep(100 * time.Millisecond)
logIDs, err := lom.masterFor(testCtx, firstIDs)
if !reflect.DeepEqual(logIDs, test.want1) {
t.Fatalf("masterFor(factory=%T)=%v,%v; want %v,_", test.factory, logIDs, err, test.want1)
}
// Now add extra IDs and re-check.
lom.masterFor(testCtx, allIDs)
if _, err := lom.masterFor(testCtx, allIDs); err != nil {
t.Error(err)
}
time.Sleep(100 * time.Millisecond)
logIDs, err = lom.masterFor(testCtx, allIDs)
if !reflect.DeepEqual(logIDs, test.want2) {
Expand Down
12 changes: 9 additions & 3 deletions log/sequencer_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ func TestSequencerManagerSingleLogNoLeaves(t *testing.T) {
}

sm := NewSequencerManager(registry, zeroDuration)
sm.ExecutePass(ctx, logID, createTestInfo(registry))
if _, err := sm.ExecutePass(ctx, logID, createTestInfo(registry)); err != nil {
t.Error(err)
}
}

func TestSequencerManagerCachesSigners(t *testing.T) {
Expand Down Expand Up @@ -181,7 +183,9 @@ func TestSequencerManagerSingleLogOneLeaf(t *testing.T) {
}

sm := NewSequencerManager(registry, zeroDuration)
sm.ExecutePass(ctx, logID, createTestInfo(registry))
if _, err := sm.ExecutePass(ctx, logID, createTestInfo(registry)); err != nil {
t.Error(err)
}
}

// cmpMatcher is a custom gomock.Matcher that uses cmp.Equal combined with a
Expand Down Expand Up @@ -224,7 +228,9 @@ func TestSequencerManagerGuardWindow(t *testing.T) {
}

sm := NewSequencerManager(registry, time.Second*5)
sm.ExecutePass(ctx, logID, createTestInfo(registry))
if _, err := sm.ExecutePass(ctx, logID, createTestInfo(registry)); err != nil {
t.Error(err)
}
}

func createTestInfo(registry extension.Registry) *OperationInfo {
Expand Down
Loading