Skip to content

chore: update golang to 1.24.1 #17035

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

Merged
merged 42 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5df49f9
feat: update Go version to 1.24.1
Mar 21, 2025
83e79be
refactor: simplify Go 1.24.1 update
Mar 21, 2025
57a47e0
revert: simplify change to go version only
Mar 21, 2025
8187c9e
fix: update guts dependency to support Go 1.24.1
Mar 21, 2025
5aaf404
fix: update golangci-lint tool for Go 1.24.1
Mar 21, 2025
d7160ae
fix: temporarily disable Go linting due to Go 1.24.1 compatibility is…
Mar 21, 2025
3c3aa21
fix: update golangci-lint to v1.57.1 for Go 1.24.1 compatibility
Mar 21, 2025
4710808
fix: upgrade golangci-lint to v1.64.8
Mar 21, 2025
2bcb38a
revert: restore original lint/go implementation in Makefile
Mar 21, 2025
651d489
fix: restore original Makefile structure with continue-on-error for l…
Mar 21, 2025
77b2908
chore: remove continue-on-error behavior from lint/go
Mar 21, 2025
226e838
update golangci rules
sreya Mar 24, 2025
02fd64a
fix config
sreya Mar 24, 2025
3d07833
ignore unused parameters in tests
sreya Mar 25, 2025
75be2c3
update golangci rules
sreya Mar 25, 2025
2b19287
more updates
sreya Mar 25, 2025
ee44d98
fix: Add #nosec G115 annotations to address integer overflow conversi…
sreya Mar 25, 2025
f8af6a8
fix: Add more #nosec G115 annotations for integer overflow warnings
sreya Mar 25, 2025
3cf7102
fix: address G115 integer overflow linter warnings for Go 1.24.1
sreya Mar 25, 2025
527df65
fix: address more G115 integer overflow linter warnings
sreya Mar 25, 2025
7d11352
refactor: replace if-else chains with switch statements
sreya Mar 25, 2025
59e1b9c
fix: resolve unused parameter linter issues for Go 1.24.1 compatibility
sreya Mar 25, 2025
bb5aa17
fix: resolve unused-parameter warnings for Go 1.24.1 compatibility
sreya Mar 26, 2025
0b3571a
errname and fix changes
sreya Mar 26, 2025
7f93228
more fixes
sreya Mar 26, 2025
792b4b5
fix compilation error
sreya Mar 26, 2025
a4f441a
fix: resolve G115 integer overflow conversion warnings for Go 1.24.1 …
sreya Mar 26, 2025
5caf54d
fix: convert if-else chains to switch statements for Go 1.24.1 compat…
sreya Mar 26, 2025
d9b665c
fix abhorrent edits
sreya Mar 26, 2025
7e0ceec
fix more linting rules
sreya Mar 26, 2025
1530bfb
fix agent
sreya Mar 26, 2025
9ae5514
fix more stuff
sreya Mar 26, 2025
e2e1e17
fix test
sreya Mar 26, 2025
f3f5755
fix: resolve remaining redefines-builtin-id linting issues
sreya Mar 26, 2025
9b0a218
fix appendAssign
sreya Mar 26, 2025
d3581a8
fix: resolve deferUnlambda linting issues by simplifying defer statem…
sreya Mar 26, 2025
1bb7942
fix ifelse
sreya Mar 26, 2025
31311d3
fix assignOp linting errors
Mar 26, 2025
3b93057
Revert "fix: resolve deferUnlambda linting issues by simplifying defe…
sreya Mar 26, 2025
3a4ac1e
unlambda && make gen
sreya Mar 26, 2025
38de0cf
don't commit dbmock
sreya Mar 26, 2025
3afeb90
make gen
sreya Mar 26, 2025
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
Prev Previous commit
Next Next commit
errname and fix changes
  • Loading branch information
sreya committed Mar 26, 2025
commit 0b3571a580f8a25acdeae6d3cc4c197f950d63b7
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ issues:

run:
timeout: 10m
skip-files:
- scripts/rules.go

# Over time, add more and more linters from
# https://golangci-lint.run/usage/linters/ as the code improves.
Expand Down
2 changes: 1 addition & 1 deletion cli/cliui/cliui.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/coder/pretty"
)

var Canceled = xerrors.New("canceled")
var ErrCanceled = xerrors.New("canceled")

// DefaultStyles compose visual elements of the UI.
var DefaultStyles Styles
Expand Down
4 changes: 2 additions & 2 deletions cli/cliui/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func Prompt(inv *serpent.Invocation, opts PromptOptions) (string, error) {
return "", err
case line := <-lineCh:
if opts.IsConfirm && line != "yes" && line != "y" {
return line, xerrors.Errorf("got %q: %w", line, Canceled)
return line, xerrors.Errorf("got %q: %w", line, ErrCanceled)
}
if opts.Validate != nil {
err := opts.Validate(line)
Expand All @@ -139,7 +139,7 @@ func Prompt(inv *serpent.Invocation, opts PromptOptions) (string, error) {
case <-interrupt:
// Print a newline so that any further output starts properly on a new line.
_, _ = fmt.Fprintln(inv.Stdout)
return "", Canceled
return "", ErrCanceled
}
}

Expand Down
2 changes: 1 addition & 1 deletion cli/cliui/provisionerjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func ProvisionerJob(ctx context.Context, wr io.Writer, opts ProvisionerJobOption
switch job.Status {
case codersdk.ProvisionerJobCanceled:
jobMutex.Unlock()
return Canceled
return ErrCanceled
case codersdk.ProvisionerJobSucceeded:
jobMutex.Unlock()
return nil
Expand Down
2 changes: 1 addition & 1 deletion cli/cliui/provisionerjob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func newProvisionerJob(t *testing.T) provisionerJobTest {
defer close(done)
err := inv.WithContext(context.Background()).Run()
if err != nil {
assert.ErrorIs(t, err, cliui.Canceled)
assert.ErrorIs(t, err, cliui.ErrCanceled)
}
}()
t.Cleanup(func() {
Expand Down
4 changes: 2 additions & 2 deletions cli/cliui/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func Select(inv *serpent.Invocation, opts SelectOptions) (string, error) {
}

if model.canceled {
return "", Canceled
return "", ErrCanceled
}

return model.selected, nil
Expand Down Expand Up @@ -360,7 +360,7 @@ func MultiSelect(inv *serpent.Invocation, opts MultiSelectOptions) ([]string, er
}

if model.canceled {
return nil, Canceled
return nil, ErrCanceled
}

return model.selectedOptions(), nil
Expand Down
2 changes: 1 addition & 1 deletion cli/configssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (r *RootCmd) configSSH() *serpent.Command {
IsConfirm: true,
})
if err != nil {
if line == "" && xerrors.Is(err, cliui.Canceled) {
if line == "" && xerrors.Is(err, cliui.ErrCanceled) {
return nil
}
// Selecting "no" will use the last config.
Expand Down
2 changes: 1 addition & 1 deletion cli/externalauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fi
if err != nil {
return err
}
return cliui.Canceled
return cliui.ErrCanceled
}
if extra != "" {
if extAuth.TokenExtra == nil {
Expand Down
2 changes: 1 addition & 1 deletion cli/externalauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestExternalAuth(t *testing.T) {
inv.Stdout = pty.Output()
waiter := clitest.StartWithWaiter(t, inv)
pty.ExpectMatch("https://github.com")
waiter.RequireIs(cliui.Canceled)
waiter.RequireIs(cliui.ErrCanceled)
})
t.Run("SuccessWithToken", func(t *testing.T) {
t.Parallel()
Expand Down
2 changes: 1 addition & 1 deletion cli/gitaskpass.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r *RootCmd) gitAskpass() *serpent.Command {
cliui.Warn(inv.Stderr, "Coder was unable to handle this git request. The default git behavior will be used instead.",
lines...,
)
return cliui.Canceled
return cliui.ErrCanceled
}
return xerrors.Errorf("get git token: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/gitaskpass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestGitAskpass(t *testing.T) {
pty := ptytest.New(t)
inv.Stderr = pty.Output()
err := inv.Run()
require.ErrorIs(t, err, cliui.Canceled)
require.ErrorIs(t, err, cliui.ErrCanceled)
pty.ExpectMatch("Nope!")
})

Expand Down
6 changes: 3 additions & 3 deletions cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func promptFirstUsername(inv *serpent.Invocation) (string, error) {
Text: "What " + pretty.Sprint(cliui.DefaultStyles.Field, "username") + " would you like?",
Default: currentUser.Username,
})
if errors.Is(err, cliui.Canceled) {
if errors.Is(err, cliui.ErrCanceled) {
return "", nil
}
if err != nil {
Expand All @@ -64,7 +64,7 @@ func promptFirstName(inv *serpent.Invocation) (string, error) {
Default: "",
})
if err != nil {
if errors.Is(err, cliui.Canceled) {
if errors.Is(err, cliui.ErrCanceled) {
return "", nil
}
return "", err
Expand Down Expand Up @@ -508,7 +508,7 @@ func promptTrialInfo(inv *serpent.Invocation, fieldName string) (string, error)
},
})
if err != nil {
if errors.Is(err, cliui.Canceled) {
if errors.Is(err, cliui.ErrCanceled) {
return "", nil
}
return "", err
Expand Down
2 changes: 1 addition & 1 deletion cli/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (r *RootCmd) openVSCode() *serpent.Command {
})
if err != nil {
if xerrors.Is(err, context.Canceled) {
return cliui.Canceled
return cliui.ErrCanceled
}
return xerrors.Errorf("agent: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (r *RootCmd) RunWithSubcommands(subcommands []*serpent.Command) {
code = exitErr.code
err = exitErr.err
}
if errors.Is(err, cliui.Canceled) {
if errors.Is(err, cliui.ErrCanceled) {
//nolint:revive
os.Exit(code)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (r *RootCmd) ssh() *serpent.Command {
})
if err != nil {
if xerrors.Is(err, context.Canceled) {
return cliui.Canceled
return cliui.ErrCanceled
}
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func TestSSH(t *testing.T) {

cmdDone := tGo(t, func() {
err := inv.WithContext(ctx).Run()
assert.ErrorIs(t, err, cliui.Canceled)
assert.ErrorIs(t, err, cliui.ErrCanceled)
})
pty.ExpectMatch(wantURL)
cancel()
Expand Down
2 changes: 1 addition & 1 deletion cli/vscodessh.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (r *RootCmd) vscodeSSH() *serpent.Command {
})
if err != nil {
if xerrors.Is(err, context.Canceled) {
return cliui.Canceled
return cliui.ErrCanceled
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/cliui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func main() {
return nil
},
})
if errors.Is(err, cliui.Canceled) {
if errors.Is(err, cliui.ErrCanceled) {
return nil
}
if err != nil {
Expand All @@ -100,7 +100,7 @@ func main() {
Default: cliui.ConfirmYes,
IsConfirm: true,
})
if errors.Is(err, cliui.Canceled) {
if errors.Is(err, cliui.ErrCanceled) {
return nil
}
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions coderd/autobuild/lifecycle_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1219,10 +1219,9 @@ func mustProvisionWorkspaceWithParameters(t *testing.T, client *codersdk.Client,
return coderdtest.MustWorkspace(t, client, ws.ID)
}

func mustSchedule(t *testing.T, _ string) *cron.Schedule {
func mustSchedule(t *testing.T, s string) *cron.Schedule {
t.Helper()
// Always use the same schedule string for consistency
sched, err := cron.Weekly("CRON_TZ=UTC 0 * * * *")
sched, err := cron.Weekly(s)
require.NoError(t, err)
return sched
}
Expand Down
8 changes: 3 additions & 5 deletions coderd/coderdtest/authorize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,11 @@ func fuzzAuthzPrep(t *testing.T, prep rbac.PreparedAuthorized, n int, action pol
return pairs
}

func fuzzAuthz(t *testing.T, sub rbac.Subject, rec rbac.Authorizer, _ int) []coderdtest.ActionObjectPair {
func fuzzAuthz(t *testing.T, sub rbac.Subject, rec rbac.Authorizer, n int) []coderdtest.ActionObjectPair {
t.Helper()
// Always use 10 pairs for consistency
const numPairs = 10
pairs := make([]coderdtest.ActionObjectPair, 0, numPairs)
pairs := make([]coderdtest.ActionObjectPair, 0, n)

for i := 0; i < numPairs; i++ {
for i := 0; i < n; i++ {
p := coderdtest.ActionObjectPair{Action: coderdtest.RandomRBACAction(), Object: coderdtest.RandomRBACObject()}
_ = rec.Authorize(context.Background(), sub, p.Action, p.Object)
pairs = append(pairs, p)
Expand Down
6 changes: 2 additions & 4 deletions coderd/cryptokeys/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,10 @@ func decodedSecret(t *testing.T, key codersdk.CryptoKey) []byte {
return secret
}

func generateKey(t *testing.T, _ int) string {
func generateKey(t *testing.T, size int) string {
t.Helper()

// Always use 64 bytes for consistency
const keySize = 64
key := make([]byte, keySize)
key := make([]byte, size)
_, err := rand.Read(key)
require.NoError(t, err)

Expand Down
24 changes: 12 additions & 12 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ var _ database.Store = (*querier)(nil)

const wrapname = "dbauthz.querier"

// NoActorError is returned if no actor is present in the context.
var NoActorError = xerrors.Errorf("no authorization actor in context")
// ErrNoActor is returned if no actor is present in the context.
var ErrNoActor = xerrors.Errorf("no authorization actor in context")

// NotAuthorizedError is a sentinel error that unwraps to sql.ErrNoRows.
// This allows the internal error to be read by the caller if needed. Otherwise
Expand Down Expand Up @@ -69,7 +69,7 @@ func IsNotAuthorizedError(err error) bool {
if err == nil {
return false
}
if xerrors.Is(err, NoActorError) {
if xerrors.Is(err, ErrNoActor) {
return true
}

Expand Down Expand Up @@ -140,7 +140,7 @@ func (q *querier) Wrappers() []string {
func (q *querier) authorizeContext(ctx context.Context, action policy.Action, object rbac.Objecter) error {
act, ok := ActorFromContext(ctx)
if !ok {
return NoActorError
return ErrNoActor
}

err := q.auth.Authorize(ctx, act, action, object.RBACObject())
Expand Down Expand Up @@ -466,7 +466,7 @@ func insertWithAction[
// Fetch the rbac subject
act, ok := ActorFromContext(ctx)
if !ok {
return empty, NoActorError
return empty, ErrNoActor
}

// Authorize the action
Expand Down Expand Up @@ -544,7 +544,7 @@ func fetchWithAction[
// Fetch the rbac subject
act, ok := ActorFromContext(ctx)
if !ok {
return empty, NoActorError
return empty, ErrNoActor
}

// Fetch the database object
Expand Down Expand Up @@ -620,7 +620,7 @@ func fetchAndQuery[
// Fetch the rbac subject
act, ok := ActorFromContext(ctx)
if !ok {
return empty, NoActorError
return empty, ErrNoActor
}

// Fetch the database object
Expand Down Expand Up @@ -654,7 +654,7 @@ func fetchWithPostFilter[
// Fetch the rbac subject
act, ok := ActorFromContext(ctx)
if !ok {
return empty, NoActorError
return empty, ErrNoActor
}

// Fetch the database object
Expand All @@ -673,7 +673,7 @@ func fetchWithPostFilter[
func prepareSQLFilter(ctx context.Context, authorizer rbac.Authorizer, action policy.Action, resourceType string) (rbac.PreparedAuthorized, error) {
act, ok := ActorFromContext(ctx)
if !ok {
return nil, NoActorError
return nil, ErrNoActor
}

return authorizer.Prepare(ctx, act, action, resourceType)
Expand Down Expand Up @@ -752,7 +752,7 @@ func (*querier) convertToDeploymentRoles(names []string) []rbac.RoleIdentifier {
func (q *querier) canAssignRoles(ctx context.Context, orgID uuid.UUID, added, removed []rbac.RoleIdentifier) error {
actor, ok := ActorFromContext(ctx)
if !ok {
return NoActorError
return ErrNoActor
}

roleAssign := rbac.ResourceAssignRole
Expand Down Expand Up @@ -961,7 +961,7 @@ func (q *querier) customRoleEscalationCheck(ctx context.Context, actor rbac.Subj
func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole) error {
act, ok := ActorFromContext(ctx)
if !ok {
return NoActorError
return ErrNoActor
}

// Org permissions require an org role
Expand Down Expand Up @@ -3896,7 +3896,7 @@ func (q *querier) UpdateProvisionerJobWithCancelByID(ctx context.Context, arg da
// Only owners can cancel workspace builds
actor, ok := ActorFromContext(ctx)
if !ok {
return NoActorError
return ErrNoActor
}
if !slice.Contains(actor.Roles.Names(), rbac.RoleOwner()) {
return xerrors.Errorf("only owners can cancel workspace builds")
Expand Down
2 changes: 1 addition & 1 deletion coderd/database/dbauthz/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (s *MethodTestSuite) NoActorErrorTest(callMethod func(ctx context.Context)
s.Run("AsRemoveActor", func() {
// Call without any actor
_, err := callMethod(context.Background())
s.ErrorIs(err, dbauthz.NoActorError, "method should return NoActorError error when no actor is provided")
s.ErrorIs(err, dbauthz.ErrNoActor, "method should return NoActorError error when no actor is provided")
})
}

Expand Down
Loading