Skip to content

Mandatory golangci lint#3720

Open
moskyb wants to merge 2 commits intomainfrom
mandatory-golangci-lint
Open

Mandatory golangci lint#3720
moskyb wants to merge 2 commits intomainfrom
mandatory-golangci-lint

Conversation

@moskyb
Copy link
Contributor

@moskyb moskyb commented Feb 25, 2026

Description

We've had golangci-lint as a soft-failing step in CI for a long time, and I think it's time we turned it on for real. However, we have a lot of code that's not up to scratch.

That's ok though! I threw $10 at the sourcegraph corporation and they did a perfectly adequate job of fixing all of our GCIL errors.

Changes

  • errcheck: Added //nolint:errcheck pragmas with explanatory comments for deferred Close(), os.Remove(), logger/test writes, http.Serve() in goroutines, and similar best-effort operations
  • staticcheck ST1005: Lowercased error string prefixes and removed trailing punctuation per Go conventions
  • staticcheck SA1019: Removed deprecated net.Error.Temporary() call (timeout check already covers it)
  • staticcheck QF1008: Simplified p.Plugin.DisplayName()p.DisplayName() using promoted method
  • unused: Removed unused constants and variables

Testing

  • Tests have run locally (with go test ./...). Buildkite employees may check this if the pipeline has run automatically.
  • Code is formatted (with go tool gofumpt -extra -w .)

Disclosures / Credits

Look, none of this was me, it was all Amp, but i'm so glad for that.

Token: "bkaj_job-token",
}

jobWithMismatchedSecrets = api.Job{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unused? Should it be used?

func (m *multipartStreamer) WriteFile(key, artifactPath string, fh http.File) error {
if m.reader != nil {
return errors.New("WriteFile can't be called multiple times")
return errors.New("writeFile can't be called multiple times")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WriteFile is referring to the method called WriteFile. Maybe the error should be rephrased:

Suggested change
return errors.New("writeFile can't be called multiple times")
return errors.New("file already written")

Comment on lines +144 to +147
return nil, fmt.Errorf("%s your HTTP proxy settings do not grant a NO_PROXY=169.254.169.254 exemption for the instance metadata service, instance profile credentials may not be retrievable via your HTTP proxy", errorTitle)
}

return nil, fmt.Errorf("%s You can authenticate by setting Buildkite environment variables (BUILDKITE_S3_ACCESS_KEY_ID, BUILDKITE_S3_SECRET_ACCESS_KEY, BUILDKITE_S3_PROFILE), AWS environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_PROFILE), Web Identity environment variables (AWS_ROLE_ARN, AWS_ROLE_SESSION_NAME, AWS_WEB_IDENTITY_TOKEN_FILE), or if running on AWS EC2 ensuring network access to the EC2 Instance Metadata Service to use an instance profile’s IAM Role credentials.", errorTitle)
return nil, fmt.Errorf("%s you can authenticate by setting Buildkite environment variables (BUILDKITE_S3_ACCESS_KEY_ID, BUILDKITE_S3_SECRET_ACCESS_KEY, BUILDKITE_S3_PROFILE), AWS environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_PROFILE), Web Identity environment variables (AWS_ROLE_ARN, AWS_ROLE_SESSION_NAME, AWS_WEB_IDENTITY_TOKEN_FILE), or if running on AWS EC2 ensuring network access to the EC2 Instance Metadata Service to use an instance profile’s IAM Role credentials", errorTitle)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another example complicated by errorTitle being the actual start of the error string, with the rest being "hint to the user".

What if we added an ErrorWithHint type that could be examined when the error is printed?

type ErrorWithHint struct {
	Err error
	Hint string
}

func (e ErrorWithHint) Unwrap() error { return e.Err }
func (e ErrorWithHint) Error() string { return e.Err.String() }

//...

if h := new(ErrorWithHint); errors.As(err, h) {
	fmt.Fprintln(c.App.ErrWriter, h.Hint)
}

func (d S3Downloader) Start(ctx context.Context) error {
if d.conf.S3Client == nil {
return fmt.Errorf("S3Downloader for %s: S3Client is nil", d.conf.S3Path)
return fmt.Errorf("s3Downloader for %s: S3Client is nil", d.conf.S3Path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again this is capitalised because it's referring to the type. Not sure what the best solution is here, but this seems wrong.

tempDir, err := filepath.EvalSymlinks(tempDirRaw)
if err != nil {
return nil, fmt.Errorf("EvalSymlinks for temp dir: %w", err)
return nil, fmt.Errorf("evalSymlinks for temp dir: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("evalSymlinks for temp dir: %w", err)
return nil, fmt.Errorf("evaluating symlinks for temp dir: %w", err)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants