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

Upgrade to golangci-lint 1.60.1 #548

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions internal/util/hashutil/hash_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ func NewAdvisoryLockHash(configuredPrefix int32) *AdvisoryLockHash {
// functions like `pg_advisory_xact_lock`.
func (h *AdvisoryLockHash) Key() int64 {
if h.configuredPrefix == 0 {
return int64(h.hash64.Sum64()) // overflow allowed
// Overflow is okay and allowed.
return int64(h.hash64.Sum64()) //nolint:gosec
}

return int64(uint64(h.configuredPrefix)<<32 | uint64(h.hash32.Sum32())) // overflow allowed
// Overflow is okay and allowed.
return int64(uint64(h.configuredPrefix)<<32 | uint64(h.hash32.Sum32())) //nolint:gosec
}

// Write writes bytes to the underlying hash.
Expand Down
2 changes: 1 addition & 1 deletion job_list_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (p *JobListParams) First(count int) *JobListParams {
panic("count must be <= 10000")
}
paramsCopy := p.copy()
paramsCopy.paginationCount = int32(count)
paramsCopy.paginationCount = int32(count) //nolint:gosec
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bounds are checked a little higher up in this function.

return paramsCopy
}

Expand Down
2 changes: 1 addition & 1 deletion producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func Test_Producer_CanSafelyCompleteJobsWhileFetchingNewOnes(t *testing.T) {
default:
}
numActiveJobs := producer.numJobsActive.Load()
if numActiveJobs > int32(producer.config.MaxWorkers) {
if int(numActiveJobs) > producer.config.MaxWorkers {
panic(fmt.Sprintf("producer exceeded MaxWorkerCount=%d, actual count=%d", producer.config.MaxWorkers, numActiveJobs))
}
}
Expand Down
2 changes: 1 addition & 1 deletion queue_list_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ func (p *QueueListParams) First(count int) *QueueListParams {
panic("count must be <= 10000")
}
result := p.copy()
result.paginationCount = int32(count)
result.paginationCount = int32(count) //nolint:gosec
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bounds are checked a little higher up in this function.

return result
}
28 changes: 14 additions & 14 deletions riverdriver/riverdatabasesql/river_database_sql_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (e *Executor) JobDeleteBefore(ctx context.Context, params *riverdriver.JobD
func (e *Executor) JobGetAvailable(ctx context.Context, params *riverdriver.JobGetAvailableParams) ([]*rivertype.JobRow, error) {
jobs, err := dbsqlc.New().JobGetAvailable(ctx, e.dbtx, &dbsqlc.JobGetAvailableParams{
AttemptedBy: params.AttemptedBy,
Max: int32(params.Max),
Max: int32(min(params.Max, math.MaxInt32)), //nolint:gosec
Queue: params.Queue,
})
if err != nil {
Expand Down Expand Up @@ -190,7 +190,7 @@ func (e *Executor) JobGetByKindMany(ctx context.Context, kind []string) ([]*rive
}

func (e *Executor) JobGetStuck(ctx context.Context, params *riverdriver.JobGetStuckParams) ([]*rivertype.JobRow, error) {
jobs, err := dbsqlc.New().JobGetStuck(ctx, e.dbtx, &dbsqlc.JobGetStuckParams{Max: int32(params.Max), StuckHorizon: params.StuckHorizon})
jobs, err := dbsqlc.New().JobGetStuck(ctx, e.dbtx, &dbsqlc.JobGetStuckParams{Max: int32(min(params.Max, math.MaxInt32)), StuckHorizon: params.StuckHorizon}) //nolint:gosec
if err != nil {
return nil, interpretError(err)
}
Expand All @@ -202,9 +202,9 @@ func (e *Executor) JobInsertFast(ctx context.Context, params *riverdriver.JobIns
Args: string(params.EncodedArgs),
CreatedAt: params.CreatedAt,
Kind: params.Kind,
MaxAttempts: int16(min(params.MaxAttempts, math.MaxInt16)),
MaxAttempts: int16(min(params.MaxAttempts, math.MaxInt16)), //nolint:gosec
Metadata: valutil.ValOrDefault(string(params.Metadata), "{}"),
Priority: int16(min(params.Priority, math.MaxInt16)),
Priority: int16(min(params.Priority, math.MaxInt16)), //nolint:gosec
Queue: params.Queue,
ScheduledAt: params.ScheduledAt,
State: dbsqlc.RiverJobState(params.State),
Expand Down Expand Up @@ -245,9 +245,9 @@ func (e *Executor) JobInsertFastMany(ctx context.Context, params []*riverdriver.

insertJobsParams.Args[i] = valutil.ValOrDefault(string(params.EncodedArgs), "{}")
insertJobsParams.Kind[i] = params.Kind
insertJobsParams.MaxAttempts[i] = int16(min(params.MaxAttempts, math.MaxInt16))
insertJobsParams.MaxAttempts[i] = int16(min(params.MaxAttempts, math.MaxInt16)) //nolint:gosec
insertJobsParams.Metadata[i] = valutil.ValOrDefault(string(params.Metadata), "{}")
insertJobsParams.Priority[i] = int16(min(params.Priority, math.MaxInt16))
insertJobsParams.Priority[i] = int16(min(params.Priority, math.MaxInt16)) //nolint:gosec
insertJobsParams.Queue[i] = params.Queue
insertJobsParams.ScheduledAt[i] = scheduledAt
insertJobsParams.State[i] = dbsqlc.RiverJobState(params.State)
Expand All @@ -264,16 +264,16 @@ func (e *Executor) JobInsertFastMany(ctx context.Context, params []*riverdriver.

func (e *Executor) JobInsertFull(ctx context.Context, params *riverdriver.JobInsertFullParams) (*rivertype.JobRow, error) {
job, err := dbsqlc.New().JobInsertFull(ctx, e.dbtx, &dbsqlc.JobInsertFullParams{
Attempt: int16(params.Attempt),
Attempt: int16(min(params.Attempt, math.MaxInt16)), //nolint:gosec
AttemptedAt: params.AttemptedAt,
Args: string(params.EncodedArgs),
CreatedAt: params.CreatedAt,
Errors: sliceutil.Map(params.Errors, func(e []byte) string { return string(e) }),
FinalizedAt: params.FinalizedAt,
Kind: params.Kind,
MaxAttempts: int16(min(params.MaxAttempts, math.MaxInt16)),
MaxAttempts: int16(min(params.MaxAttempts, math.MaxInt16)), //nolint:gosec
Metadata: valutil.ValOrDefault(string(params.Metadata), "{}"),
Priority: int16(min(params.Priority, math.MaxInt16)),
Priority: int16(min(params.Priority, math.MaxInt16)), //nolint:gosec
Queue: params.Queue,
ScheduledAt: params.ScheduledAt,
State: dbsqlc.RiverJobState(params.State),
Expand All @@ -291,9 +291,9 @@ func (e *Executor) JobInsertUnique(ctx context.Context, params *riverdriver.JobI
Args: string(params.EncodedArgs),
CreatedAt: params.CreatedAt,
Kind: params.Kind,
MaxAttempts: int16(min(params.MaxAttempts, math.MaxInt16)),
MaxAttempts: int16(min(params.MaxAttempts, math.MaxInt16)), //nolint:gosec
Metadata: valutil.ValOrDefault(string(params.Metadata), "{}"),
Priority: int16(min(params.Priority, math.MaxInt16)),
Priority: int16(min(params.Priority, math.MaxInt16)), //nolint:gosec
Queue: params.Queue,
ScheduledAt: params.ScheduledAt,
State: dbsqlc.RiverJobState(params.State),
Expand Down Expand Up @@ -502,7 +502,7 @@ func (e *Executor) JobSetCompleteIfRunningMany(ctx context.Context, params *rive
func (e *Executor) JobSetStateIfRunning(ctx context.Context, params *riverdriver.JobSetStateIfRunningParams) (*rivertype.JobRow, error) {
var maxAttempts int16
if params.MaxAttempts != nil {
maxAttempts = int16(*params.MaxAttempts)
maxAttempts = int16(min(*params.MaxAttempts, math.MaxInt16)) //nolint:gosec
}

job, err := dbsqlc.New().JobSetStateIfRunning(ctx, e.dbtx, &dbsqlc.JobSetStateIfRunningParams{
Expand All @@ -529,7 +529,7 @@ func (e *Executor) JobUpdate(ctx context.Context, params *riverdriver.JobUpdateP
AttemptedAtDoUpdate: params.AttemptedAtDoUpdate,
AttemptedAt: params.AttemptedAt,
AttemptDoUpdate: params.AttemptDoUpdate,
Attempt: int16(params.Attempt),
Attempt: int16(min(params.Attempt, math.MaxInt16)), //nolint:gosec
ErrorsDoUpdate: params.ErrorsDoUpdate,
Errors: sliceutil.Map(params.Errors, func(e []byte) string { return string(e) }),
FinalizedAtDoUpdate: params.FinalizedAtDoUpdate,
Expand Down Expand Up @@ -732,7 +732,7 @@ func (e *Executor) QueueGet(ctx context.Context, name string) (*rivertype.Queue,
}

func (e *Executor) QueueList(ctx context.Context, limit int) ([]*rivertype.Queue, error) {
internalQueues, err := dbsqlc.New().QueueList(ctx, e.dbtx, int32(limit))
internalQueues, err := dbsqlc.New().QueueList(ctx, e.dbtx, int32(min(limit, math.MaxInt32))) //nolint:gosec
if err != nil {
return nil, interpretError(err)
}
Expand Down
28 changes: 14 additions & 14 deletions riverdriver/riverpgxv5/river_pgx_v5_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (e *Executor) JobDeleteBefore(ctx context.Context, params *riverdriver.JobD
func (e *Executor) JobGetAvailable(ctx context.Context, params *riverdriver.JobGetAvailableParams) ([]*rivertype.JobRow, error) {
jobs, err := dbsqlc.New().JobGetAvailable(ctx, e.dbtx, &dbsqlc.JobGetAvailableParams{
AttemptedBy: params.AttemptedBy,
Max: int32(params.Max),
Max: int32(min(params.Max, math.MaxInt32)), //nolint:gosec
Queue: params.Queue,
})
if err != nil {
Expand Down Expand Up @@ -185,7 +185,7 @@ func (e *Executor) JobGetByKindMany(ctx context.Context, kind []string) ([]*rive
}

func (e *Executor) JobGetStuck(ctx context.Context, params *riverdriver.JobGetStuckParams) ([]*rivertype.JobRow, error) {
jobs, err := dbsqlc.New().JobGetStuck(ctx, e.dbtx, &dbsqlc.JobGetStuckParams{Max: int32(params.Max), StuckHorizon: params.StuckHorizon})
jobs, err := dbsqlc.New().JobGetStuck(ctx, e.dbtx, &dbsqlc.JobGetStuckParams{Max: int32(min(params.Max, math.MaxInt32)), StuckHorizon: params.StuckHorizon}) //nolint:gosec
if err != nil {
return nil, interpretError(err)
}
Expand All @@ -197,9 +197,9 @@ func (e *Executor) JobInsertFast(ctx context.Context, params *riverdriver.JobIns
Args: params.EncodedArgs,
CreatedAt: params.CreatedAt,
Kind: params.Kind,
MaxAttempts: int16(min(params.MaxAttempts, math.MaxInt16)),
MaxAttempts: int16(min(params.MaxAttempts, math.MaxInt16)), //nolint:gosec
Metadata: params.Metadata,
Priority: int16(min(params.Priority, math.MaxInt16)),
Priority: int16(min(params.Priority, math.MaxInt16)), //nolint:gosec
Queue: params.Queue,
ScheduledAt: params.ScheduledAt,
State: dbsqlc.RiverJobState(params.State),
Expand Down Expand Up @@ -236,9 +236,9 @@ func (e *Executor) JobInsertFastMany(ctx context.Context, params []*riverdriver.
insertJobsParams[i] = &dbsqlc.JobInsertFastManyCopyFromParams{
Args: params.EncodedArgs,
Kind: params.Kind,
MaxAttempts: int16(min(params.MaxAttempts, math.MaxInt16)),
MaxAttempts: int16(min(params.MaxAttempts, math.MaxInt16)), //nolint:gosec
Metadata: metadata,
Priority: int16(min(params.Priority, math.MaxInt16)),
Priority: int16(min(params.Priority, math.MaxInt16)), //nolint:gosec
Queue: params.Queue,
ScheduledAt: scheduledAt,
State: dbsqlc.RiverJobState(params.State),
Expand All @@ -256,16 +256,16 @@ func (e *Executor) JobInsertFastMany(ctx context.Context, params []*riverdriver.

func (e *Executor) JobInsertFull(ctx context.Context, params *riverdriver.JobInsertFullParams) (*rivertype.JobRow, error) {
job, err := dbsqlc.New().JobInsertFull(ctx, e.dbtx, &dbsqlc.JobInsertFullParams{
Attempt: int16(params.Attempt),
Attempt: int16(min(params.Attempt, math.MaxInt16)), //nolint:gosec
AttemptedAt: params.AttemptedAt,
Args: params.EncodedArgs,
CreatedAt: params.CreatedAt,
Errors: params.Errors,
FinalizedAt: params.FinalizedAt,
Kind: params.Kind,
MaxAttempts: int16(min(params.MaxAttempts, math.MaxInt16)),
MaxAttempts: int16(min(params.MaxAttempts, math.MaxInt16)), //nolint:gosec
Metadata: params.Metadata,
Priority: int16(min(params.Priority, math.MaxInt16)),
Priority: int16(min(params.Priority, math.MaxInt16)), //nolint:gosec
Queue: params.Queue,
ScheduledAt: params.ScheduledAt,
State: dbsqlc.RiverJobState(params.State),
Expand All @@ -283,9 +283,9 @@ func (e *Executor) JobInsertUnique(ctx context.Context, params *riverdriver.JobI
Args: params.EncodedArgs,
CreatedAt: params.CreatedAt,
Kind: params.Kind,
MaxAttempts: int16(min(params.MaxAttempts, math.MaxInt16)),
MaxAttempts: int16(min(params.MaxAttempts, math.MaxInt16)), //nolint:gosec
Metadata: params.Metadata,
Priority: int16(min(params.Priority, math.MaxInt16)),
Priority: int16(min(params.Priority, math.MaxInt16)), //nolint:gosec
Queue: params.Queue,
ScheduledAt: params.ScheduledAt,
State: dbsqlc.RiverJobState(params.State),
Expand Down Expand Up @@ -391,7 +391,7 @@ func (e *Executor) JobSetCompleteIfRunningMany(ctx context.Context, params *rive
func (e *Executor) JobSetStateIfRunning(ctx context.Context, params *riverdriver.JobSetStateIfRunningParams) (*rivertype.JobRow, error) {
var maxAttempts int16
if params.MaxAttempts != nil {
maxAttempts = int16(*params.MaxAttempts)
maxAttempts = int16(min(*params.MaxAttempts, math.MaxInt16)) //nolint:gosec
}

job, err := dbsqlc.New().JobSetStateIfRunning(ctx, e.dbtx, &dbsqlc.JobSetStateIfRunningParams{
Expand All @@ -418,7 +418,7 @@ func (e *Executor) JobUpdate(ctx context.Context, params *riverdriver.JobUpdateP
AttemptedAtDoUpdate: params.AttemptedAtDoUpdate,
AttemptedAt: params.AttemptedAt,
AttemptDoUpdate: params.AttemptDoUpdate,
Attempt: int16(params.Attempt),
Attempt: int16(min(params.Attempt, math.MaxInt16)), //nolint:gosec
ErrorsDoUpdate: params.ErrorsDoUpdate,
Errors: params.Errors,
FinalizedAtDoUpdate: params.FinalizedAtDoUpdate,
Expand Down Expand Up @@ -621,7 +621,7 @@ func (e *Executor) QueueGet(ctx context.Context, name string) (*rivertype.Queue,
}

func (e *Executor) QueueList(ctx context.Context, limit int) ([]*rivertype.Queue, error) {
internalQueues, err := dbsqlc.New().QueueList(ctx, e.dbtx, int32(limit))
internalQueues, err := dbsqlc.New().QueueList(ctx, e.dbtx, int32(min(limit, math.MaxInt32))) //nolint:gosec
if err != nil {
return nil, interpretError(err)
}
Expand Down
Loading