Skip to content

Commit 5f9fdf3

Browse files
authored
Merge pull request #1978 from alexandear/enable-errcheck-lint
Enable errcheck linter; fix lint issues
2 parents c97380d + 966d918 commit 5f9fdf3

File tree

9 files changed

+32
-21
lines changed

9 files changed

+32
-21
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ linters:
3636
# - dogsled
3737
# - dupl
3838
- dupword
39-
# - errcheck
39+
- errcheck
4040
# - errorlint
4141
# - exhaustive
4242
# - exhaustivestruct

cmd/limactl/disk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ $ limactl disk create DISK --size SIZE [--format qcow2]
5151
RunE: diskCreateAction,
5252
}
5353
diskCreateCommand.Flags().String("size", "", "configure the disk size")
54-
diskCreateCommand.MarkFlagRequired("size")
54+
_ = diskCreateCommand.MarkFlagRequired("size")
5555
diskCreateCommand.Flags().String("format", "qcow2", "specify the disk format")
5656
return diskCreateCommand
5757
}

cmd/limactl/gendoc.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ func gendocAction(cmd *cobra.Command, args []string) error {
6161
}
6262
}
6363
if output != "" && prefix != "" {
64-
replaceAll(dir, output, prefix)
64+
if err := replaceAll(dir, output, prefix); err != nil {
65+
return err
66+
}
6567
}
66-
replaceAll(dir, homeDir, "~")
67-
return nil
68+
return replaceAll(dir, homeDir, "~")
6869
}
6970

7071
func genMan(cmd *cobra.Command, dir string) error {

pkg/guestagent/kubernetesservice/kubernetesservice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (s *ServiceWatcher) getServiceInformer() cache.SharedIndexInformer {
5656
func (s *ServiceWatcher) Start() {
5757
const retryInterval = 10 * time.Second
5858
const pollImmediately = false
59-
wait.PollUntilContextCancel(context.TODO(), retryInterval, pollImmediately, func(ctx context.Context) (done bool, err error) {
59+
_ = wait.PollUntilContextCancel(context.TODO(), retryInterval, pollImmediately, func(ctx context.Context) (done bool, err error) {
6060
kubeClient, err := tryGetKubeClient()
6161
if err != nil {
6262
logrus.Tracef("failed to get kube client: %v, will retry in %v", err, retryInterval)

pkg/guestagent/kubernetesservice/kubernetesservice_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ func TestGetPorts(t *testing.T) {
2727
serviceCreatedCh := make(chan struct{}, 1)
2828
kubeClient, informerFactory := newFakeKubeClient()
2929
serviceInformer := informerFactory.Core().V1().Services().Informer()
30-
serviceInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
30+
_, err := serviceInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
3131
AddFunc: func(obj interface{}) { serviceCreatedCh <- struct{}{} },
3232
})
33+
assert.NilError(t, err)
3334
informerFactory.Start(ctx.Done())
3435
serviceWatcher := NewServiceWatcher()
3536
serviceWatcher.setServiceInformer(serviceInformer)
@@ -41,7 +42,7 @@ func TestGetPorts(t *testing.T) {
4142
}
4243
cases := []testCase{
4344
{
44-
name: "nodePort serivce",
45+
name: "nodePort service",
4546
service: corev1.Service{
4647
ObjectMeta: metav1.ObjectMeta{Name: "nodeport"},
4748
Spec: corev1.ServiceSpec{

pkg/qemu/qemu_driver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func (l *LimaQemuDriver) shutdownQEMU(ctx context.Context, timeout time.Duration
325325
select {
326326
case qWaitErr := <-qWaitCh:
327327
logrus.WithError(qWaitErr).Info("QEMU has exited")
328-
l.removeVNCFiles()
328+
_ = l.removeVNCFiles()
329329
return errors.Join(qWaitErr, l.killVhosts())
330330
case <-deadline:
331331
}
@@ -346,7 +346,7 @@ func (l *LimaQemuDriver) killQEMU(_ context.Context, _ time.Duration, qCmd *exec
346346
}
347347
qemuPIDPath := filepath.Join(l.Instance.Dir, filenames.PIDFile(*l.Yaml.VMType))
348348
_ = os.RemoveAll(qemuPIDPath)
349-
l.removeVNCFiles()
349+
_ = l.removeVNCFiles()
350350
return errors.Join(qWaitErr, l.killVhosts())
351351
}
352352

pkg/start/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func watchHostAgentEvents(ctx context.Context, inst *store.Instance, haStdoutPat
263263
} else {
264264
logrus.Infof("READY. Run `%s` to open the shell.", LimactlShellCmd(inst.Name))
265265
}
266-
ShowMessage(inst)
266+
_ = ShowMessage(inst)
267267
err = nil
268268
return true
269269
}

pkg/store/instance_test.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ var tableTwo = "NAME STATUS SSH VMTYPE ARCH CPUS M
6565
func TestPrintInstanceTable(t *testing.T) {
6666
var buf bytes.Buffer
6767
instances := []*Instance{&instance}
68-
PrintInstances(&buf, instances, "table", nil)
68+
err := PrintInstances(&buf, instances, "table", nil)
69+
assert.NilError(t, err)
6970
assert.Equal(t, table, buf.String())
7071
}
7172

@@ -74,7 +75,8 @@ func TestPrintInstanceTableEmu(t *testing.T) {
7475
instance1 := instance
7576
instance1.Arch = "unknown"
7677
instances := []*Instance{&instance1}
77-
PrintInstances(&buf, instances, "table", nil)
78+
err := PrintInstances(&buf, instances, "table", nil)
79+
assert.NilError(t, err)
7880
assert.Equal(t, tableEmu, buf.String())
7981
}
8082

@@ -85,23 +87,26 @@ func TestPrintInstanceTableHome(t *testing.T) {
8587
instance1 := instance
8688
instance1.Dir = filepath.Join(u.HomeDir, "dir")
8789
instances := []*Instance{&instance1}
88-
PrintInstances(&buf, instances, "table", nil)
90+
err = PrintInstances(&buf, instances, "table", nil)
91+
assert.NilError(t, err)
8992
assert.Equal(t, tableHome, buf.String())
9093
}
9194

9295
func TestPrintInstanceTable60(t *testing.T) {
9396
var buf bytes.Buffer
9497
instances := []*Instance{&instance}
9598
options := PrintOptions{TerminalWidth: 60}
96-
PrintInstances(&buf, instances, "table", &options)
99+
err := PrintInstances(&buf, instances, "table", &options)
100+
assert.NilError(t, err)
97101
assert.Equal(t, table60, buf.String())
98102
}
99103

100104
func TestPrintInstanceTable80SameArch(t *testing.T) {
101105
var buf bytes.Buffer
102106
instances := []*Instance{&instance}
103107
options := PrintOptions{TerminalWidth: 80}
104-
PrintInstances(&buf, instances, "table", &options)
108+
err := PrintInstances(&buf, instances, "table", &options)
109+
assert.NilError(t, err)
105110
assert.Equal(t, table80i, buf.String())
106111
}
107112

@@ -111,23 +116,26 @@ func TestPrintInstanceTable80DiffArch(t *testing.T) {
111116
instance1.Arch = limayaml.NewArch("unknown")
112117
instances := []*Instance{&instance1}
113118
options := PrintOptions{TerminalWidth: 80}
114-
PrintInstances(&buf, instances, "table", &options)
119+
err := PrintInstances(&buf, instances, "table", &options)
120+
assert.NilError(t, err)
115121
assert.Equal(t, table80d, buf.String())
116122
}
117123

118124
func TestPrintInstanceTable100(t *testing.T) {
119125
var buf bytes.Buffer
120126
instances := []*Instance{&instance}
121127
options := PrintOptions{TerminalWidth: 100}
122-
PrintInstances(&buf, instances, "table", &options)
128+
err := PrintInstances(&buf, instances, "table", &options)
129+
assert.NilError(t, err)
123130
assert.Equal(t, table100, buf.String())
124131
}
125132

126133
func TestPrintInstanceTableAll(t *testing.T) {
127134
var buf bytes.Buffer
128135
instances := []*Instance{&instance}
129136
options := PrintOptions{TerminalWidth: 40, AllFields: true}
130-
PrintInstances(&buf, instances, "table", &options)
137+
err := PrintInstances(&buf, instances, "table", &options)
138+
assert.NilError(t, err)
131139
assert.Equal(t, tableAll, buf.String())
132140
}
133141

@@ -143,6 +151,7 @@ func TestPrintInstanceTableTwo(t *testing.T) {
143151
instance2.Arch = limayaml.AARCH64
144152
instances := []*Instance{&instance1, &instance2}
145153
options := PrintOptions{TerminalWidth: 80}
146-
PrintInstances(&buf, instances, "table", &options)
154+
err := PrintInstances(&buf, instances, "table", &options)
155+
assert.NilError(t, err)
147156
assert.Equal(t, tableTwo, buf.String())
148157
}

pkg/vz/vm_darwin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*virtualMachineWra
104104
wrapper.mu.Lock()
105105
wrapper.stopped = true
106106
wrapper.mu.Unlock()
107-
usernetClient.UnExposeSSH(driver.SSHLocalPort)
107+
_ = usernetClient.UnExposeSSH(driver.SSHLocalPort)
108108
errCh <- errors.New("vz driver state stopped")
109109
default:
110110
logrus.Debugf("[VZ] - vm state change: %q", newState)

0 commit comments

Comments
 (0)