Unverified Commit 36fe5853 authored by Pedro Pombeiro's avatar Pedro Pombeiro
Browse files

Enable errcheck linter

Closes #25159
parent 13bb940d
......@@ -15,6 +15,8 @@ output:
print-linter-name: true
linters-settings:
errcheck:
check-type-assertions: true
gocognit:
min-complexity: 15
goconst:
......@@ -75,6 +77,7 @@ linters:
- bodyclose
- deadcode
- dogsled
- errcheck
- funlen
- gocognit
- goconst
......@@ -125,17 +128,20 @@ issues:
- linters:
- golint
text: "don't use an underscore in package name"
- path: ".*_test.go"
linters:
- goconst
- path: ".*_test.go"
linters:
- bodyclose
- funlen
- gocognit
- goconst
- path: ".*_test.go"
text: "Error return value is not checked"
linters:
- errcheck
- path: ".*_test.go"
text: "regexpMust"
linters:
- errcheck
- gocritic
- path: referees/prometheus_api.go
linters:
......
......@@ -74,7 +74,7 @@ func TestCreateAdapter(t *testing.T) {
assert.NoError(t, err)
}
factories.Register(
_ = factories.Register(
"additional-adapter",
func(config *common.CacheConfig, timeout time.Duration, objectName string) (Adapter, error) {
return new(MockAdapter), nil
......
......@@ -106,7 +106,7 @@ func (c *ExecCommand) Execute(context *cli.Context) {
case 1:
c.Job = context.Args().Get(0)
default:
cli.ShowSubcommandHelp(context)
_ = cli.ShowSubcommandHelp(context)
os.Exit(1)
return
}
......
......@@ -53,7 +53,7 @@ func (m *testNetwork) DownloadArtifacts(
defer file.Close()
archive := zip.NewWriter(file)
archive.Create(artifactsTestArchivedFile)
_, _ = archive.Create(artifactsTestArchivedFile)
archive.Close()
}
return m.downloadState
......@@ -61,7 +61,7 @@ func (m *testNetwork) DownloadArtifacts(
func (m *testNetwork) consumeZipUpload(reader io.Reader) common.UploadState {
var buffer bytes.Buffer
io.Copy(&buffer, reader)
_, _ = io.Copy(&buffer, reader)
archive, err := zip.NewReader(bytes.NewReader(buffer.Bytes()), int64(buffer.Len()))
if err != nil {
logrus.Warningln(err)
......@@ -79,7 +79,7 @@ func (m *testNetwork) consumeZipUpload(reader io.Reader) common.UploadState {
func (m *testNetwork) consumeGzipUpload(reader io.Reader) common.UploadState {
var buffer bytes.Buffer
io.Copy(&buffer, reader)
_, _ = io.Copy(&buffer, reader)
stream := bytes.NewReader(buffer.Bytes())
......@@ -112,7 +112,7 @@ func (m *testNetwork) consumeGzipUpload(reader io.Reader) common.UploadState {
}
func (m *testNetwork) consumeRawUpload(reader io.Reader) common.UploadState {
io.Copy(ioutil.Discard, reader)
_, _ = io.Copy(ioutil.Discard, reader)
m.uploadedFiles = append(m.uploadedFiles, "raw")
m.uploadFormat = common.ArtifactFormatRaw
......
......@@ -41,12 +41,12 @@ type ArtifactsUploaderCommand struct {
func (c *ArtifactsUploaderCommand) generateZipArchive(w *io.PipeWriter) {
err := archives.CreateZipArchive(w, c.sortedFiles())
w.CloseWithError(err)
_ = w.CloseWithError(err)
}
func (c *ArtifactsUploaderCommand) generateGzipStream(w *io.PipeWriter) {
err := archives.CreateGzipArchive(w, c.sortedFiles())
w.CloseWithError(err)
_ = w.CloseWithError(err)
}
func (c *ArtifactsUploaderCommand) openRawStream() (io.ReadCloser, error) {
......
......@@ -94,7 +94,7 @@ func testServeCache(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Last-Modified", time.Now().Format(http.TimeFormat))
archive := zip.NewWriter(w)
archive.Create(cacheExtractorTestArchivedFile)
_, _ = archive.Create(cacheExtractorTestArchivedFile)
archive.Close()
}
......
......@@ -54,6 +54,6 @@ func TestCacheInit_NoArguments(t *testing.T) {
args := []string{os.Args[0], "cache-init"}
assert.Panics(t, func() {
newCacheInitTestApp().Run(args)
_ = newCacheInitTestApp().Run(args)
})
}
......@@ -31,7 +31,7 @@ func testServiceCommandRun(command func(*cli.Context), args ...string) {
}
args = append([]string{"binary", "test-command"}, args...)
app.Run(args)
_ = app.Run(args)
}
type getServiceArgumentsTestCase struct {
......
......@@ -412,7 +412,7 @@ func (b *Build) executeScript(ctx context.Context, executor Executor) error {
timeoutCtx, timeoutCancel := context.WithTimeout(ctx, AfterScriptTimeout)
defer timeoutCancel()
b.executeStage(timeoutCtx, BuildStageAfterScript, executor)
_ = b.executeStage(timeoutCtx, BuildStageAfterScript, executor)
}
// Execute post script (cache store, artifacts upload)
......@@ -737,7 +737,10 @@ func (b *Build) Run(globalConfig *Config, trace JobTrace) (err error) {
return errors.New("executor not found")
}
provider.GetFeatures(&b.ExecutorFeatures)
err = provider.GetFeatures(&b.ExecutorFeatures)
if err != nil {
return fmt.Errorf("retrieving executor features: %w", err)
}
executor, err = b.executeBuildSection(executor, options, provider)
......
......@@ -415,7 +415,7 @@ func (e *executor) createService(
containerName := fmt.Sprintf("%s-%s-%d", e.getProjectUniqRandomizedName(), serviceSlug, serviceIndex)
// this will fail potentially some builds if there's name collision
e.removeContainer(e.Context, containerName)
_ = e.removeContainer(e.Context, containerName)
config := &container.Config{
Image: serviceImage.ID,
......@@ -521,7 +521,7 @@ func (e *executor) waitForServices() {
for _, service := range e.services {
wg.Add(1)
go func(service *types.Container) {
e.waitForServiceContainer(service, time.Duration(waitForServicesTimeout)*time.Second)
_ = e.waitForServiceContainer(service, time.Duration(waitForServicesTimeout)*time.Second)
wg.Done()
}(service)
}
......@@ -689,7 +689,7 @@ func (e *executor) createContainer(
networkConfig := e.networkConfig(aliases)
// this will fail potentially some builds if there's name collision
e.removeContainer(e.Context, containerName)
_ = e.removeContainer(e.Context, containerName)
e.Debugln("Creating container", containerName, "...")
resp, err := e.client.ContainerCreate(e.Context, config, hostConfig, networkConfig, containerName)
......@@ -810,7 +810,7 @@ func (e *executor) startAndWatchContainer(ctx context.Context, id string, input
stdinErrCh := make(chan error)
go func() {
_, errCopy := io.Copy(hijacked.Conn, input)
hijacked.CloseWrite()
_ = hijacked.CloseWrite()
if errCopy != nil {
stdinErrCh <- errCopy
}
......@@ -1155,7 +1155,7 @@ func (e *executor) Cleanup() {
remove := func(id string) {
wg.Add(1)
go func() {
e.removeContainer(ctx, id)
_ = e.removeContainer(ctx, id)
wg.Done()
}()
}
......@@ -1242,7 +1242,7 @@ func (e *executor) runServiceHealthCheckContainer(service *types.Container, time
if err != nil {
return fmt.Errorf("create service container: %w", err)
}
defer e.removeContainer(e.Context, resp.ID)
defer func() { _ = e.removeContainer(e.Context, resp.ID) }()
e.Debugln(fmt.Sprintf("Starting service healthcheck container %s (%s)...", containerName, resp.ID))
err = e.client.ContainerStart(e.Context, resp.ID, types.ContainerStartOptions{})
......@@ -1368,7 +1368,7 @@ func (e *executor) waitForServiceContainer(service *types.Container, timeout tim
buffer.WriteString("\n")
buffer.WriteString(helpers.ANSI_YELLOW + "*********" + helpers.ANSI_RESET + "\n")
buffer.WriteString("\n")
io.Copy(e.Trace, &buffer)
_, _ = io.Copy(e.Trace, &buffer)
return err
}
......@@ -1387,7 +1387,7 @@ func (e *executor) readContainerLogs(containerID string) string {
}
defer hijacked.Close()
stdcopy.StdCopy(&containerBuffer, &containerBuffer, hijacked)
_, _ = stdcopy.StdCopy(&containerBuffer, &containerBuffer, hijacked)
containerLog := containerBuffer.String()
return strings.TrimSpace(containerLog)
}
......@@ -975,7 +975,7 @@ func testDockerVersion(t *testing.T, version string) {
}
defer func() {
exec.Command("docker", "rm", "-f", "-v", id).Run()
_ = exec.Command("docker", "rm", "-f", "-v", id).Run()
}()
t.Log("Getting address of", version, "...")
......
......@@ -53,7 +53,9 @@ func TestDockerLinuxSetter(t *testing.T) {
testContainer, err := client.ContainerCreate(context.Background(), config, hostConfig, nil, containerName)
require.NoError(t, err)
defer client.ContainerRemove(context.Background(), testContainer.ID, types.ContainerRemoveOptions{Force: true})
defer func() {
_ = client.ContainerRemove(context.Background(), testContainer.ID, types.ContainerRemoveOptions{Force: true})
}()
err = client.ContainerStart(context.Background(), testContainer.ID, types.ContainerStartOptions{})
require.NoError(t, err)
......
......@@ -68,7 +68,7 @@ func (m *machineDetails) writeDebugInformation() {
details.Time = time.Now().String()
details.CreatedAgo = time.Since(m.Created)
data := helpers.ToYAML(&details)
ioutil.WriteFile("machines/"+details.Details.Name+".yml", []byte(data), 0600)
_ = ioutil.WriteFile("machines/"+details.Details.Name+".yml", []byte(data), 0600)
}
func (m *machineDetails) logger() *logrus.Entry {
......
......@@ -41,7 +41,7 @@ func filterMachineList(machines []string, filter string) (newMachines []string)
func newMachineName(config *common.RunnerConfig) string {
r := make([]byte, 4)
rand.Read(r)
_, _ = rand.Read(r)
t := time.Now().Unix()
return fmt.Sprintf(machineFilter(config), fmt.Sprintf("%d-%x", t, r))
}
......@@ -36,11 +36,12 @@ func (m *machineProvider) machineDetails(name string, acquire bool) *machineDeta
details, ok := m.details[name]
if !ok {
now := time.Now()
details = &machineDetails{
Name: name,
Created: time.Now(),
Used: time.Now(),
LastSeen: time.Now(),
Created: now,
Used: now,
LastSeen: now,
UsedCount: 1, // any machine that we find we mark as already used
State: machineStateIdle,
}
......@@ -87,7 +88,7 @@ func (m *machineProvider) create(
WithField("time", time.Since(started)).
WithError(err).
Errorln("Machine creation failed")
m.remove(details.Name, "Failed to create")
_ = m.remove(details.Name, "Failed to create")
} else {
details.State = state
details.Used = time.Now()
......@@ -118,7 +119,7 @@ func (m *machineProvider) findFreeMachine(skipCache bool, machines ...string) (d
// Check if node is running
canConnect := m.machine.CanConnect(name, skipCache)
if !canConnect {
m.remove(name, "machine is unavailable")
_ = m.remove(name, "machine is unavailable")
continue
}
return details
......@@ -274,7 +275,7 @@ func (m *machineProvider) updateMachines(
if err == nil {
validMachines = append(validMachines, name)
} else {
m.remove(details.Name, err)
_ = m.remove(details.Name, err)
}
data.Add(details)
......
......@@ -22,6 +22,6 @@ func (d *dockerTTY) Write(p []byte) (int, error) {
func (d *dockerTTY) Close() error {
d.hijackedResp.Close()
d.hijackedResp.CloseWrite()
_ = d.hijackedResp.CloseWrite()
return nil
}
......@@ -393,7 +393,7 @@ func testKubernetesClient(version string, httpClient *http.Client) *kubernetes.C
func testVersionAndCodec() (version string, codec runtime.Codec) {
scheme := runtime.NewScheme()
scheme.AddIgnoredConversionType(&metav1.TypeMeta{}, &metav1.TypeMeta{})
_ = scheme.AddIgnoredConversionType(&metav1.TypeMeta{}, &metav1.TypeMeta{})
scheme.AddKnownTypes(
api.SchemeGroupVersion,
&api.Pod{},
......
......@@ -111,7 +111,7 @@ func (s *executor) createVM() error {
// remove invalid template (removed?)
templateStatus, _ := prl.Status(templateName)
if templateStatus == prl.Invalid {
prl.Unregister(templateName)
_ = prl.Unregister(templateName)
}
if !prl.Exist(templateName) {
......@@ -277,7 +277,7 @@ func unregisterInvalidVM(vmName string) {
// remove invalid VM (removed?)
vmStatus, _ := prl.Status(vmName)
if vmStatus == prl.Invalid {
prl.Unregister(vmName)
_ = prl.Unregister(vmName)
}
}
......@@ -365,10 +365,10 @@ func (s *executor) Cleanup() {
s.sshCommand.Cleanup()
if s.vmName != "" {
prl.Kill(s.vmName)
_ = prl.Kill(s.vmName)
if s.Config.Parallels.DisableSnapshots || !s.provisioned {
prl.Delete(s.vmName)
_ = prl.Delete(s.vmName)
}
}
......
......@@ -75,6 +75,6 @@ func TestSharedEnv(t *testing.T) {
provider := common.GetExecutorProvider("ssh")
features := &common.FeaturesInfo{}
provider.GetFeatures(features)
_ = provider.GetFeatures(features)
assert.True(t, features.Shared)
}
......@@ -83,7 +83,7 @@ func (s *StubSSHServer) mainLoop(listener net.Listener) {
}
// upgrade to ssh connection
cryptoSSH.NewServerConn(conn, s.Config)
_, _, _, _ = cryptoSSH.NewServerConn(conn, s.Config)
// This is enough just for handling incoming connections
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment