diff --git a/CHANGELOG.md b/CHANGELOG.md index bbd4a5518..7131144af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Fixed cases when some option is nil + ## v3.57.1 * Added logs over query service internals * Changed `trace.Query` events diff --git a/balancers/config.go b/balancers/config.go index ee70ec57f..8bc38199c 100644 --- a/balancers/config.go +++ b/balancers/config.go @@ -116,9 +116,9 @@ func FromConfig(config string, opts ...fromConfigOption) *balancerConfig.Config b *balancerConfig.Config err error ) - for _, o := range opts { - if o != nil { - o(&h) + for _, opt := range opts { + if opt != nil { + opt(&h) } } diff --git a/config/config.go b/config/config.go index e3578ee58..be50b5137 100644 --- a/config/config.go +++ b/config/config.go @@ -268,9 +268,9 @@ func ExcludeGRPCCodesForPessimization(codes ...grpcCodes.Code) Option { func New(opts ...Option) *Config { c := defaultConfig() - for _, o := range opts { - if o != nil { - o(c) + for _, opt := range opts { + if opt != nil { + opt(c) } } @@ -281,9 +281,9 @@ func New(opts ...Option) *Config { // With makes copy of current Config with specified options func (c *Config) With(opts ...Option) *Config { - for _, o := range opts { - if o != nil { - o(c) + for _, opt := range opts { + if opt != nil { + opt(c) } } c.meta = meta.New( diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index 97beef0d9..c3a6902fe 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -86,9 +86,9 @@ func New(opts ...option) logBackoff { b := logBackoff{ r: xrand.New(xrand.WithLock()), } - for _, o := range opts { - if o != nil { - o(&b) + for _, opt := range opts { + if opt != nil { + opt(&b) } } diff --git a/internal/conn/conn.go b/internal/conn/conn.go index cec97c202..9e84ca977 100644 --- a/internal/conn/conn.go +++ b/internal/conn/conn.go @@ -500,9 +500,9 @@ func newConn(e endpoint.Endpoint, config Config, opts ...option) *conn { done: make(chan struct{}), } c.state.Store(uint32(Created)) - for _, o := range opts { - if o != nil { - o(c) + for _, opt := range opts { + if opt != nil { + opt(c) } } diff --git a/internal/coordination/config/config.go b/internal/coordination/config/config.go index ea23c4b6b..ac684475f 100644 --- a/internal/coordination/config/config.go +++ b/internal/coordination/config/config.go @@ -37,9 +37,9 @@ func New(opts ...Option) Config { c := Config{ trace: &trace.Coordination{}, } - for _, o := range opts { - if o != nil { - o(&c) + for _, opt := range opts { + if opt != nil { + opt(&c) } } diff --git a/internal/credentials/access_error.go b/internal/credentials/access_error.go index 70f801bc3..777bc3d80 100644 --- a/internal/credentials/access_error.go +++ b/internal/credentials/access_error.go @@ -94,10 +94,12 @@ func AccessError(msg string, err error, opts ...authErrorOption) error { buffer.WriteString(msg) buffer.WriteString(" (") for i, opt := range opts { - if i != 0 { - buffer.WriteString(",") + if opt != nil { + if i != 0 { + buffer.WriteString(",") + } + opt.applyAuthErrorOption(buffer) } - opt.applyAuthErrorOption(buffer) } buffer.WriteString("): %w") diff --git a/internal/credentials/access_token.go b/internal/credentials/access_token.go index 2d1365827..c6e205f32 100644 --- a/internal/credentials/access_token.go +++ b/internal/credentials/access_token.go @@ -32,7 +32,9 @@ func NewAccessTokenCredentials(token string, opts ...AccessTokenCredentialsOptio sourceInfo: stack.Record(1), } for _, opt := range opts { - opt.ApplyAccessTokenCredentialsOption(c) + if opt != nil { + opt.ApplyAccessTokenCredentialsOption(c) + } } return c diff --git a/internal/credentials/anonymous.go b/internal/credentials/anonymous.go index 7bd75f4c3..88d937095 100644 --- a/internal/credentials/anonymous.go +++ b/internal/credentials/anonymous.go @@ -28,7 +28,9 @@ func NewAnonymousCredentials(opts ...AnonymousCredentialsOption) *Anonymous { sourceInfo: stack.Record(1), } for _, opt := range opts { - opt.ApplyAnonymousCredentialsOption(c) + if opt != nil { + opt.ApplyAnonymousCredentialsOption(c) + } } return c diff --git a/internal/credentials/static.go b/internal/credentials/static.go index 56e80277d..298785bf1 100644 --- a/internal/credentials/static.go +++ b/internal/credentials/static.go @@ -47,7 +47,9 @@ func NewStaticCredentials(user, password, endpoint string, opts ...StaticCredent sourceInfo: stack.Record(1), } for _, opt := range opts { - opt.ApplyStaticCredentialsOption(c) + if opt != nil { + opt.ApplyStaticCredentialsOption(c) + } } return c diff --git a/internal/discovery/config/config.go b/internal/discovery/config/config.go index 6ea99d21b..782f3b6b2 100644 --- a/internal/discovery/config/config.go +++ b/internal/discovery/config/config.go @@ -29,9 +29,9 @@ func New(opts ...Option) *Config { interval: DefaultInterval, trace: &trace.Discovery{}, } - for _, o := range opts { - if o != nil { - o(c) + for _, opt := range opts { + if opt != nil { + opt(c) } } diff --git a/internal/endpoint/endpoint.go b/internal/endpoint/endpoint.go index cdaba3710..823d721d0 100644 --- a/internal/endpoint/endpoint.go +++ b/internal/endpoint/endpoint.go @@ -110,13 +110,10 @@ func (e *endpoint) LastUpdated() time.Time { func (e *endpoint) Touch(opts ...Option) { e.mu.Lock() defer e.mu.Unlock() - for _, o := range append( - []Option{ - withLastUpdated(time.Now()), - }, - opts..., - ) { - o(e) + for _, opt := range append([]Option{withLastUpdated(time.Now())}, opts...) { + if opt != nil { + opt(e) + } } } @@ -163,9 +160,9 @@ func New(address string, opts ...Option) *endpoint { address: address, lastUpdated: time.Now(), } - for _, o := range opts { - if o != nil { - o(e) + for _, opt := range opts { + if opt != nil { + opt(e) } } diff --git a/internal/meta/meta.go b/internal/meta/meta.go index 4f1564732..640fb63fe 100644 --- a/internal/meta/meta.go +++ b/internal/meta/meta.go @@ -24,9 +24,9 @@ func New( credentials: credentials, database: database, } - for _, o := range opts { - if o != nil { - o(m) + for _, opt := range opts { + if opt != nil { + opt(m) } } diff --git a/internal/meta/trace_id.go b/internal/meta/trace_id.go index 926722579..182c57dac 100644 --- a/internal/meta/trace_id.go +++ b/internal/meta/trace_id.go @@ -19,7 +19,9 @@ func TraceID(ctx context.Context, opts ...func(opts *newTraceIDOpts)) (context.C } options := newTraceIDOpts{newRandom: uuid.NewRandom} for _, opt := range opts { - opt(&options) + if opt != nil { + opt(&options) + } } uuid, err := options.newRandom() if err != nil { diff --git a/internal/pool/pool.go b/internal/pool/pool.go index 780d09ef3..b6a504d47 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -66,7 +66,9 @@ func New[T any]( done: make(chan struct{}), } for _, opt := range opts { - opt(p) + if opt != nil { + opt(p) + } } return p diff --git a/internal/query/config/config.go b/internal/query/config/config.go index 8163d519e..79fd4ccef 100644 --- a/internal/query/config/config.go +++ b/internal/query/config/config.go @@ -30,9 +30,9 @@ type Config struct { func New(opts ...Option) *Config { c := defaults() - for _, o := range opts { - if o != nil { - o(c) + for _, opt := range opts { + if opt != nil { + opt(c) } } diff --git a/internal/query/options/execute.go b/internal/query/options/execute.go index ab5d5230e..b742e1717 100644 --- a/internal/query/options/execute.go +++ b/internal/query/options/execute.go @@ -125,7 +125,9 @@ func ExecuteSettings(opts ...ExecuteOption) (settings *Execute) { settings.commonExecuteSettings = defaultCommonExecuteSettings() settings.txControl = tx.DefaultTxControl() for _, opt := range opts { - opt.applyExecuteOption(settings) + if opt != nil { + opt.applyExecuteOption(settings) + } } return settings @@ -168,7 +170,9 @@ func TxExecuteSettings(id string, opts ...TxExecuteOption) (settings *txExecuteS ExecuteSettings: ExecuteSettings(WithTxControl(tx.NewControl(tx.WithTxID(id)))), } for _, opt := range opts { - opt.applyTxExecuteOption(settings) + if opt != nil { + opt.applyTxExecuteOption(settings) + } } return settings diff --git a/internal/query/options/retry.go b/internal/query/options/retry.go index 67ede7866..b604152e3 100644 --- a/internal/query/options/retry.go +++ b/internal/query/options/retry.go @@ -112,7 +112,9 @@ func ParseDoOpts(t *trace.Query, opts ...DoOption) (s *doSettings) { } for _, opt := range opts { - opt.applyDoOption(s) + if opt != nil { + opt.applyDoOption(s) + } } return s @@ -127,7 +129,9 @@ func ParseDoTxOpts(t *trace.Query, opts ...DoTxOption) (s *doTxSettings) { } for _, opt := range opts { - opt.applyDoTxOption(s) + if opt != nil { + opt.applyDoTxOption(s) + } } return s diff --git a/internal/query/scanner/struct.go b/internal/query/scanner/struct.go index d5b03de0b..0576670e8 100644 --- a/internal/query/scanner/struct.go +++ b/internal/query/scanner/struct.go @@ -40,7 +40,9 @@ func (s StructScanner) ScanStruct(dst interface{}, opts ...ScanStructOption) err AllowMissingFieldsInStruct: false, } for _, opt := range opts { - opt.applyScanStructOption(&settings) + if opt != nil { + opt.applyScanStructOption(&settings) + } } ptr := reflect.ValueOf(dst) if ptr.Kind() != reflect.Pointer { diff --git a/internal/query/tx/control.go b/internal/query/tx/control.go index 5b71b021e..f6e6f15d5 100644 --- a/internal/query/tx/control.go +++ b/internal/query/tx/control.go @@ -56,7 +56,9 @@ func (opts beginTxOptions) applyTxSelector(a *allocator.Allocator, txControl *Yd selector := a.QueryTransactionControlBeginTx() selector.BeginTx = a.QueryTransactionSettings() for _, opt := range opts { - opt.ApplyTxSettingsOption(a, selector.BeginTx) + if opt != nil { + opt.ApplyTxSettingsOption(a, selector.BeginTx) + } } txControl.TxSelector = selector } diff --git a/internal/query/tx/settings.go b/internal/query/tx/settings.go index 15757129d..ac051d132 100644 --- a/internal/query/tx/settings.go +++ b/internal/query/tx/settings.go @@ -36,7 +36,9 @@ func (opts Settings) applyTxSelector(a *allocator.Allocator, txControl *Ydb_Quer beginTx := a.QueryTransactionControlBeginTx() beginTx.BeginTx = a.QueryTransactionSettings() for _, opt := range opts { - opt.ApplyTxSettingsOption(a, beginTx.BeginTx) + if opt != nil { + opt.ApplyTxSettingsOption(a, beginTx.BeginTx) + } } txControl.TxSelector = beginTx } @@ -44,7 +46,9 @@ func (opts Settings) applyTxSelector(a *allocator.Allocator, txControl *Ydb_Quer func (opts Settings) ToYDB(a *allocator.Allocator) *Ydb_Query.TransactionSettings { txSettings := a.QueryTransactionSettings() for _, opt := range opts { - opt.ApplyTxSettingsOption(a, txSettings) + if opt != nil { + opt.ApplyTxSettingsOption(a, txSettings) + } } return txSettings diff --git a/internal/ratelimiter/config/config.go b/internal/ratelimiter/config/config.go index 8a6dd9023..d0761f779 100644 --- a/internal/ratelimiter/config/config.go +++ b/internal/ratelimiter/config/config.go @@ -37,9 +37,9 @@ func New(opts ...Option) Config { c := Config{ trace: &trace.Ratelimiter{}, } - for _, o := range opts { - if o != nil { - o(&c) + for _, opt := range opts { + if opt != nil { + opt(&c) } } diff --git a/internal/ratelimiter/options/acquire.go b/internal/ratelimiter/options/acquire.go index d1f91d64f..1febf3e63 100644 --- a/internal/ratelimiter/options/acquire.go +++ b/internal/ratelimiter/options/acquire.go @@ -74,9 +74,9 @@ func NewAcquire(opts ...AcquireOption) Acquire { h := &acquireOptionsHolder{ acquireType: AcquireTypeDefault, } - for _, o := range opts { - if o != nil { - o(h) + for _, opt := range opts { + if opt != nil { + opt(h) } } diff --git a/internal/repeater/repeater.go b/internal/repeater/repeater.go index 4085a4690..033b44a14 100644 --- a/internal/repeater/repeater.go +++ b/internal/repeater/repeater.go @@ -108,9 +108,9 @@ func New( trace: &trace.Driver{}, } - for _, o := range opts { - if o != nil { - o(r) + for _, opt := range opts { + if opt != nil { + opt(r) } } diff --git a/internal/scheme/client.go b/internal/scheme/client.go index fea553c70..57dc9b16b 100644 --- a/internal/scheme/client.go +++ b/internal/scheme/client.go @@ -250,9 +250,9 @@ func (c *Client) ModifyPermissions( onDone(finalErr) }() var desc permissionsDesc - for _, o := range opts { - if o != nil { - o(&desc) + for _, opt := range opts { + if opt != nil { + opt(&desc) } } call := func(ctx context.Context) error { diff --git a/internal/scheme/config/config.go b/internal/scheme/config/config.go index 6a7061378..a684fc83e 100644 --- a/internal/scheme/config/config.go +++ b/internal/scheme/config/config.go @@ -50,9 +50,9 @@ func New(opts ...Option) Config { c := Config{ trace: &trace.Scheme{}, } - for _, o := range opts { - if o != nil { - o(&c) + for _, opt := range opts { + if opt != nil { + opt(&c) } } diff --git a/internal/scheme/options_test.go b/internal/scheme/options_test.go index 1f7370329..b8ef769e9 100644 --- a/internal/scheme/options_test.go +++ b/internal/scheme/options_test.go @@ -28,9 +28,9 @@ func TestSchemeOptions(t *testing.T) { } var desc permissionsDesc - for _, o := range opts { - if o != nil { - o(&desc) + for _, opt := range opts { + if opt != nil { + opt(&desc) } } diff --git a/internal/scripting/config/config.go b/internal/scripting/config/config.go index 1b8ee0ff3..35f90651d 100644 --- a/internal/scripting/config/config.go +++ b/internal/scripting/config/config.go @@ -36,9 +36,9 @@ func New(opts ...Option) Config { c := Config{ trace: &trace.Scripting{}, } - for _, o := range opts { - if o != nil { - o(&c) + for _, opt := range opts { + if opt != nil { + opt(&c) } } diff --git a/internal/stack/record.go b/internal/stack/record.go index 3ae77866f..e9555ccb5 100644 --- a/internal/stack/record.go +++ b/internal/stack/record.go @@ -87,7 +87,9 @@ func (c call) Record(opts ...recordOption) string { lambdas: true, } for _, opt := range opts { - opt(&optionsHolder) + if opt != nil { + opt(&optionsHolder) + } } name := runtime.FuncForPC(c.function).Name() var ( diff --git a/internal/table/client.go b/internal/table/client.go index 505a66f01..e3823ffc8 100644 --- a/internal/table/client.go +++ b/internal/table/client.go @@ -121,9 +121,9 @@ func withCreateSessionOnClose(onClose func(s *session)) createSessionOption { func (c *Client) createSession(ctx context.Context, opts ...createSessionOption) (s *session, err error) { options := createSessionOptions{} - for _, o := range opts { - if o != nil { - o(&options) + for _, opt := range opts { + if opt != nil { + opt(&options) } } diff --git a/internal/table/config/config.go b/internal/table/config/config.go index 5013ab332..de94fb3e6 100644 --- a/internal/table/config/config.go +++ b/internal/table/config/config.go @@ -27,9 +27,9 @@ const ( func New(opts ...Option) *Config { c := defaults() - for _, o := range opts { - if o != nil { - o(c) + for _, opt := range opts { + if opt != nil { + opt(c) } } diff --git a/internal/table/scanner/result.go b/internal/table/scanner/result.go index f0b0d0cd7..1cbc88eb6 100644 --- a/internal/table/scanner/result.go +++ b/internal/table/scanner/result.go @@ -116,9 +116,9 @@ func NewStream( recv: recv, close: onClose, } - for _, o := range opts { - if o != nil { - o(&r.baseResult) + for _, opt := range opts { + if opt != nil { + opt(&r.baseResult) } } if err := r.nextResultSetErr(ctx); err != nil { @@ -135,9 +135,9 @@ func NewUnary(sets []*Ydb.ResultSet, stats *Ydb_TableStats.QueryStats, opts ...o }, sets: sets, } - for _, o := range opts { - if o != nil { - o(&r.baseResult) + for _, opt := range opts { + if opt != nil { + opt(&r.baseResult) } } diff --git a/internal/table/session.go b/internal/table/session.go index 297afe020..0b8eba0ee 100644 --- a/internal/table/session.go +++ b/internal/table/session.go @@ -1195,7 +1195,9 @@ func (s *session) BulkUpsert(ctx context.Context, table string, rows value.Value }() for _, opt := range opts { - callOptions = append(callOptions, opt.ApplyBulkUpsertOption()...) + if opt != nil { + callOptions = append(callOptions, opt.ApplyBulkUpsertOption()...) + } } _, err = s.tableService.BulkUpsert(ctx, diff --git a/internal/topic/topicclientinternal/client.go b/internal/topic/topicclientinternal/client.go index a023b1471..976dca32d 100644 --- a/internal/topic/topicclientinternal/client.go +++ b/internal/topic/topicclientinternal/client.go @@ -52,9 +52,9 @@ func newTopicConfig(opts ...topicoptions.TopicOption) topic.Config { c := topic.Config{ Trace: &trace.Topic{}, } - for _, o := range opts { - if o != nil { - o(&c) + for _, opt := range opts { + if opt != nil { + opt(&c) } } @@ -71,9 +71,9 @@ func (c *Client) Alter(ctx context.Context, path string, opts ...topicoptions.Al req := &rawtopic.AlterTopicRequest{} req.OperationParams = c.defaultOperationParams req.Path = path - for _, o := range opts { - if o != nil { - o.ApplyAlterOption(req) + for _, opt := range opts { + if opt != nil { + opt.ApplyAlterOption(req) } } @@ -103,9 +103,9 @@ func (c *Client) Create( req.OperationParams = c.defaultOperationParams req.Path = path - for _, o := range opts { - if o != nil { - o.ApplyCreateOption(req) + for _, opt := range opts { + if opt != nil { + opt.ApplyCreateOption(req) } } @@ -136,9 +136,9 @@ func (c *Client) Describe( Path: path, } - for _, o := range opts { - if o != nil { - o(&req) + for _, opt := range opts { + if opt != nil { + opt(&req) } } @@ -176,9 +176,9 @@ func (c *Client) Drop(ctx context.Context, path string, opts ...topicoptions.Dro req.OperationParams = c.defaultOperationParams req.Path = path - for _, o := range opts { - if o != nil { - o.ApplyDropOption(&req) + for _, opt := range opts { + if opt != nil { + opt.ApplyDropOption(&req) } } diff --git a/internal/topic/topicreaderinternal/reader.go b/internal/topic/topicreaderinternal/reader.go index 030a5ca4b..b499221d1 100644 --- a/internal/topic/topicreaderinternal/reader.go +++ b/internal/topic/topicreaderinternal/reader.go @@ -258,9 +258,9 @@ func convertNewParamsToStreamConfig( cfg.ReadSelectors[i] = readSelectors[i].Clone() } - for _, f := range opts { - if f != nil { - f(&cfg) + for _, opt := range opts { + if opt != nil { + opt(&cfg) } } diff --git a/internal/xerrors/retryable.go b/internal/xerrors/retryable.go index f37bc2eb6..03b8a894d 100644 --- a/internal/xerrors/retryable.go +++ b/internal/xerrors/retryable.go @@ -77,9 +77,9 @@ func Retryable(err error, opts ...RetryableErrorOption) error { re.code = e.Code() re.name = e.Name() } - for _, o := range opts { - if o != nil { - o(re) + for _, opt := range opts { + if opt != nil { + opt(re) } } diff --git a/internal/xerrors/stacktrace.go b/internal/xerrors/stacktrace.go index d59c092e7..3140547d5 100644 --- a/internal/xerrors/stacktrace.go +++ b/internal/xerrors/stacktrace.go @@ -24,9 +24,9 @@ func WithStackTrace(err error, opts ...withStackTraceOption) error { return nil } options := withStackTraceOptions{} - for _, o := range opts { - if o != nil { - o(&options) + for _, opt := range opts { + if opt != nil { + opt(&options) } } if s, has := grpcStatus.FromError(err); has { diff --git a/internal/xrand/xrand.go b/internal/xrand/xrand.go index 10c974ef0..2f8ed0021 100644 --- a/internal/xrand/xrand.go +++ b/internal/xrand/xrand.go @@ -35,9 +35,9 @@ func New(opts ...option) Rand { r := &r{ r: rand.New(rand.NewSource(time.Now().Unix())), //nolint:gosec } - for _, o := range opts { - if o != nil { - o(r) + for _, opt := range opts { + if opt != nil { + opt(r) } } diff --git a/internal/xsql/conn.go b/internal/xsql/conn.go index d2086a309..a07a6400e 100644 --- a/internal/xsql/conn.go +++ b/internal/xsql/conn.go @@ -136,9 +136,9 @@ func newConn(ctx context.Context, c *Connector, s table.ClosableSession, opts .. cc.beginTxFuncs = map[QueryMode]beginTxFunc{ DataQueryMode: cc.beginTx, } - for _, o := range opts { - if o != nil { - o(cc) + for _, opt := range opts { + if opt != nil { + opt(cc) } } c.attach(cc) diff --git a/internal/xsql/dsn_test.go b/internal/xsql/dsn_test.go index 557072701..d28c96ac3 100644 --- a/internal/xsql/dsn_test.go +++ b/internal/xsql/dsn_test.go @@ -13,8 +13,10 @@ func TestParse(t *testing.T) { newConnector := func(opts ...ConnectorOption) *Connector { c := &Connector{} for _, opt := range opts { - if err := opt.Apply(c); err != nil { - t.Error(err) + if opt != nil { + if err := opt.Apply(c); err != nil { + t.Error(err) + } } } diff --git a/internal/xtest/manytimes.go b/internal/xtest/manytimes.go index cd84603fb..4dc7f1ccb 100644 --- a/internal/xtest/manytimes.go +++ b/internal/xtest/manytimes.go @@ -31,9 +31,9 @@ func TestManyTimes(t testing.TB, test TestFunc, opts ...TestManyTimesOption) { stopAfter: time.Second, } - for _, o := range opts { - if o != nil { - o(&options) + for _, opt := range opts { + if opt != nil { + opt(&options) } } diff --git a/log/logger.go b/log/logger.go index 962d218ab..8caf7229a 100644 --- a/log/logger.go +++ b/log/logger.go @@ -33,8 +33,10 @@ func Default(w io.Writer, opts ...simpleLoggerOption) *defaultLogger { clock: clockwork.NewRealClock(), w: w, } - for _, o := range opts { - o.applySimpleOption(l) + for _, opt := range opts { + if opt != nil { + opt.applySimpleOption(l) + } } return l @@ -104,9 +106,9 @@ func wrapLogger(l Logger, opts ...Option) *wrapper { ll := &wrapper{ logger: l, } - for _, o := range opts { - if o != nil { - o.applyHolderOption(ll) + for _, opt := range opts { + if opt != nil { + opt.applyHolderOption(ll) } } diff --git a/options.go b/options.go index 5e6176f40..bb02f36e0 100644 --- a/options.go +++ b/options.go @@ -247,9 +247,9 @@ func With(options ...config.Option) Option { // MergeOptions concatentaes provided options to one cumulative value. func MergeOptions(opts ...Option) Option { return func(ctx context.Context, c *Driver) error { - for _, o := range opts { - if o != nil { - if err := o(ctx, c); err != nil { + for _, opt := range opts { + if opt != nil { + if err := opt(ctx, c); err != nil { return xerrors.WithStackTrace(err) } } diff --git a/retry/retryable_error.go b/retry/retryable_error.go index e0778c1df..7501223dc 100644 --- a/retry/retryable_error.go +++ b/retry/retryable_error.go @@ -29,9 +29,9 @@ func RetryableError(err error, opts ...retryableErrorOption) error { return xerrors.Retryable( err, func() (retryableErrorOptions []xerrors.RetryableErrorOption) { - for _, o := range opts { - if o != nil { - retryableErrorOptions = append(retryableErrorOptions, xerrors.RetryableErrorOption(o)) + for _, opt := range opts { + if opt != nil { + retryableErrorOptions = append(retryableErrorOptions, xerrors.RetryableErrorOption(opt)) } } diff --git a/table/options/options.go b/table/options/options.go index c44d049f0..db85556a7 100644 --- a/table/options/options.go +++ b/table/options/options.go @@ -161,7 +161,9 @@ func (i index) ApplyAlterTableOption(d *AlterTableDesc, a *allocator.Allocator) Name: i.name, } for _, opt := range i.opts { - opt.ApplyIndexOption((*indexDesc)(x)) + if opt != nil { + opt.ApplyIndexOption((*indexDesc)(x)) + } } d.AddIndexes = append(d.AddIndexes, x) } @@ -171,7 +173,9 @@ func (i index) ApplyCreateTableOption(d *CreateTableDesc, a *allocator.Allocator Name: i.name, } for _, opt := range i.opts { - opt.ApplyIndexOption((*indexDesc)(x)) + if opt != nil { + opt.ApplyIndexOption((*indexDesc)(x)) + } } d.Indexes = append(d.Indexes, x) } diff --git a/table/table.go b/table/table.go index 83f915ddb..6d2305a1e 100644 --- a/table/table.go +++ b/table/table.go @@ -459,7 +459,9 @@ type ( func NewQueryParameters(opts ...ParameterOption) *QueryParameters { qp := QueryParameters(make([]*params.Parameter, len(opts))) for i, opt := range opts { - qp[i] = params.Named(opt.Name(), opt.Value()) + if opt != nil { + qp[i] = params.Named(opt.Name(), opt.Value()) + } } return &qp diff --git a/tests/integration/helpers_test.go b/tests/integration/helpers_test.go index 9184ad86c..73363250d 100644 --- a/tests/integration/helpers_test.go +++ b/tests/integration/helpers_test.go @@ -275,7 +275,9 @@ func (scope *scopeT) TableName(opts ...func(t *tableNameParams)) string { `, } for _, opt := range opts { - opt(¶ms) + if opt != nil { + opt(¶ms) + } } return scope.Cache(params.tableName, nil, func() (res interface{}, err error) { err = scope.Driver().Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) (err error) { diff --git a/testutil/session.go b/testutil/session.go index e53caedf2..d5ca81899 100644 --- a/testutil/session.go +++ b/testutil/session.go @@ -35,9 +35,9 @@ func SessionID(opts ...sessionIDOption) string { nodeID: uint32(xrand.New().Int64(math.MaxUint32)), hash: strconv.FormatInt(xrand.New().Int64(math.MaxInt64), 16), } - for _, o := range opts { - if o != nil { - o(h) + for _, opt := range opts { + if opt != nil { + opt(h) } } diff --git a/trace/details.go b/trace/details.go index faa0599e2..30a6da585 100644 --- a/trace/details.go +++ b/trace/details.go @@ -207,9 +207,9 @@ func MatchDetails(pattern string, opts ...matchDetailsOption) (d Details) { err error ) - for _, o := range opts { - if o != nil { - o(h) + for _, opt := range opts { + if opt != nil { + opt(h) } } if h.posixMatch {