Skip to content

Commit 097ac24

Browse files
resolve issue #75 (#108)
* linter: don't capitalize error strings and capitalize log * fix misspellings
1 parent 6c00500 commit 097ac24

File tree

9 files changed

+40
-18
lines changed

9 files changed

+40
-18
lines changed

.golangci.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ linters-settings:
1313
goconst:
1414
min-len: 2
1515
min-occurrences: 2
16+
revive:
17+
rules:
18+
- name: string-format
19+
severity: error
20+
disabled: false
21+
arguments:
22+
- - 'fmt.Errorf[0]'
23+
- "/^[^A-Z].*$/"
24+
- error messages must not start with capital letter
25+
- - 'log.Printf[0]'
26+
- "/^[^a-z].*$/"
27+
- log messages must not start with lowercase letter
28+
misspell:
29+
# Correct spellings using locale preferences for US or UK.
30+
# Default is to use a neutral variety of English.
31+
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
32+
locale: US
33+
ignore-words:
34+
- GitLab
1635

1736
linters:
1837
disable-all: true
@@ -40,3 +59,4 @@ linters:
4059
- nilerr
4160
- nilnil
4261
- usestdlibvars
62+
- misspell

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ BUG FIXES:
66
CHANGES:
77
* Add comment why and how we handle "NON_MASTER" vshard error.
88
* Don't support 'type Error struct' anymore.
9+
* Linter: don't capitalize error strings and capitalize log.
10+
* Fix misspellings.
911

1012
FEATURES:
1113

api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (r *Router) RouterCallImpl(ctx context.Context,
113113
if since := time.Since(timeStart); since > timeout {
114114
r.metrics().RequestDuration(since, false, false)
115115

116-
r.log().Debugf(ctx, "return result on timeout; since %s of timeout %s", since, timeout)
116+
r.log().Debugf(ctx, "Return result on timeout; since %s of timeout %s", since, timeout)
117117
if err == nil {
118118
err = fmt.Errorf("cant get call cause call impl timeout")
119119
}
@@ -136,7 +136,7 @@ func (r *Router) RouterCallImpl(ctx context.Context,
136136
continue
137137
}
138138

139-
r.log().Infof(ctx, "try call %s on replicaset %s for bucket %d", fnc, rs.info.Name, bucketID)
139+
r.log().Infof(ctx, "Try call %s on replicaset %s for bucket %d", fnc, rs.info.Name, bucketID)
140140

141141
future := rs.conn.Do(req, opts.PoolMode)
142142

@@ -146,7 +146,7 @@ func (r *Router) RouterCallImpl(ctx context.Context,
146146
return nil, nil, fmt.Errorf("got error on future.Get(): %w", err)
147147
}
148148

149-
r.log().Debugf(ctx, "got call result response data %v", respData)
149+
r.log().Debugf(ctx, "Got call result response data %v", respData)
150150

151151
if len(respData) == 0 {
152152
// vshard.storage.call(func) returns up to two values:
@@ -177,7 +177,7 @@ func (r *Router) RouterCallImpl(ctx context.Context,
177177
// So we just retry here as a temporary solution.
178178
r.metrics().RetryOnCall("bucket_migrate")
179179

180-
r.log().Debugf(ctx, "retrying fnc '%s' cause got vshard error: %v", fnc, &vshardError)
180+
r.log().Debugf(ctx, "Retrying fnc '%s' cause got vshard error: %v", fnc, &vshardError)
181181

182182
// this vshardError will be returned to a caller in case of timeout
183183
err = &vshardError

discovery.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const (
2626
)
2727

2828
// BucketsSearchMode a type, that used to define policy for BucketDiscovery method.
29-
// See type Config for futher details.
29+
// See type Config for further details.
3030
type BucketsSearchMode int
3131

3232
const (
@@ -226,7 +226,7 @@ func (r *Router) DiscoveryHandleBuckets(ctx context.Context, rs *Replicaset, buc
226226
func (r *Router) DiscoveryAllBuckets(ctx context.Context) error {
227227
t := time.Now()
228228

229-
r.log().Infof(ctx, "start discovery all buckets")
229+
r.log().Infof(ctx, "Start discovery all buckets")
230230

231231
errGr, ctx := errgroup.WithContext(ctx)
232232

@@ -273,7 +273,7 @@ func (r *Router) DiscoveryAllBuckets(ctx context.Context) error {
273273
if err != nil {
274274
return fmt.Errorf("errGr.Wait() err: %w", err)
275275
}
276-
r.log().Infof(ctx, "discovery done since: %s", time.Since(t))
276+
r.log().Infof(ctx, "Discovery done since: %s", time.Since(t))
277277

278278
return nil
279279
}
@@ -294,7 +294,7 @@ func (r *Router) cronDiscovery(ctx context.Context) {
294294

295295
// Since the current for loop should not stop until ctx->Done() event fires,
296296
// we should be able to continue execution even a panic occures.
297-
// Therefore, we should wrap everyting into anonymous function that recovers after panic.
297+
// Therefore, we should wrap everything into anonymous function that recovers after panic.
298298
// (Similar to pcall in lua/tarantool)
299299
func() {
300300
defer func() {

logger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ func (l tarantoolOptsLogger) Report(event tarantool.ConnLogKind, conn *tarantool
5757

5858
if headerOk {
5959
l.loggerf.Errorf(l.ctx, "tarantool: connection %s got unexpected resultId (%d) in response"+
60-
"(probably cancelled request)",
60+
"(probably canceled request)",
6161
conn.Addr(), header.RequestId)
6262
} else {
6363
l.loggerf.Errorf(l.ctx, "tarantool: connection %s got unexpected resultId in response"+
64-
"(probably cancelled request) (unexpected v... format): %+v",
64+
"(probably canceled request) (unexpected v... format): %+v",
6565
conn.Addr(), v)
6666
}
6767
case tarantool.LogWatchEventReadFailed:

providers/viper/provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func NewProvider(v *srcviper.Viper) *Provider {
4545
for rsName, rs := range cfg.Topology.Clusters {
4646
rsUUID, err := uuid.Parse(rs.ReplicasetUUID)
4747
if err != nil {
48-
log.Printf("cant parse replicaset uuid: %s", err)
48+
log.Printf("Can't parse replicaset uuid: %s", err)
4949

5050
os.Exit(2)
5151
}
@@ -59,7 +59,7 @@ func NewProvider(v *srcviper.Viper) *Provider {
5959

6060
instUUID, err := uuid.Parse(instInfo.Box.InstanceUUID)
6161
if err != nil {
62-
log.Printf("cant parse replicaset uuid: %s", err)
62+
log.Printf("Can't parse replicaset uuid: %s", err)
6363

6464
panic(err)
6565
}

replicaset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func CalculateEtalonBalance(replicasets []Replicaset, bucketCount uint64) error
269269

270270
// Safety check to prevent infinite loops
271271
if stepCount > replicasetCount {
272-
return fmt.Errorf("PANIC: the rebalancer is broken")
272+
return fmt.Errorf("[PANIC]: the rebalancer is broken")
273273
}
274274
}
275275

topology.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (r *Router) Topology() TopologyController {
4545
}
4646

4747
func (r *Router) AddInstance(ctx context.Context, rsID uuid.UUID, info InstanceInfo) error {
48-
r.log().Debugf(ctx, "trying to add instance %s to router topology in rs %s", info, rsID)
48+
r.log().Debugf(ctx, "Trying to add instance %s to router topology in rs %s", info, rsID)
4949

5050
err := info.Validate()
5151
if err != nil {
@@ -73,7 +73,7 @@ func (r *Router) AddInstance(ctx context.Context, rsID uuid.UUID, info InstanceI
7373
}
7474

7575
func (r *Router) RemoveInstance(ctx context.Context, rsID, instanceID uuid.UUID) error {
76-
r.log().Debugf(ctx, "trying to remove instance %s from router topology in rs %s", instanceID, rsID)
76+
r.log().Debugf(ctx, "Trying to remove instance %s from router topology in rs %s", instanceID, rsID)
7777

7878
idToReplicasetRef := r.getIDToReplicaset()
7979

@@ -86,7 +86,7 @@ func (r *Router) RemoveInstance(ctx context.Context, rsID, instanceID uuid.UUID)
8686
}
8787

8888
func (r *Router) AddReplicaset(ctx context.Context, rsInfo ReplicasetInfo, instances []InstanceInfo) error {
89-
r.log().Debugf(ctx, "trying to add replicaset %s to router topology", rsInfo)
89+
r.log().Debugf(ctx, "Trying to add replicaset %s to router topology", rsInfo)
9090

9191
idToReplicasetOld := r.getIDToReplicaset()
9292

@@ -169,7 +169,7 @@ func (r *Router) AddReplicasets(ctx context.Context, replicasets map[ReplicasetI
169169
}
170170

171171
func (r *Router) RemoveReplicaset(ctx context.Context, rsID uuid.UUID) []error {
172-
r.log().Debugf(ctx, "trying to remove replicaset %s from router topology", rsID)
172+
r.log().Debugf(ctx, "Trying to remove replicaset %s from router topology", rsID)
173173

174174
idToReplicasetOld := r.getIDToReplicaset()
175175

vshard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func NewRouter(ctx context.Context, cfg Config) (*Router, error) {
173173

174174
err = cfg.TopologyProvider.Init(router.Topology())
175175
if err != nil {
176-
router.log().Errorf(ctx, "cant create new topology provider with err: %s", err)
176+
router.log().Errorf(ctx, "Can't create new topology provider with err: %s", err)
177177

178178
return nil, fmt.Errorf("%w; cant init topology with err: %w", ErrTopologyProvider, err)
179179
}

0 commit comments

Comments
 (0)