Skip to content

Commit 59b3246

Browse files
author
Gleb Brozhe
committed
rollback internal/cmd/gtrace/writer.go and small fixes
1 parent ac95021 commit 59b3246

File tree

5 files changed

+53
-62
lines changed

5 files changed

+53
-62
lines changed

internal/cmd/gtrace/writer.go

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ func (w *Writer) composeHook(hook Hook, t1, t2, dst string) {
372372
w.line(`}`)
373373
}
374374

375+
//nolint:funlen
375376
func (w *Writer) composeHookCall(fn *Func, h1, h2 string) {
376377
w.newScope(func() {
377378
w.capture(h1, h2)
@@ -385,70 +386,57 @@ func (w *Writer) composeHookCall(fn *Func, h1, h2 string) {
385386
w.funcResults(fn)
386387
w.line(` {`)
387388
w.line(`if options.panicCallback != nil {`)
388-
w.addPanicCallback()
389-
w.line("}")
390-
if fn.HasResult() {
391-
rs := w.declareResults(fn)
392-
w.addHookCalls(fn, h1, h2, args, rs)
393-
w.addReturnStatement(fn, rs)
394-
} else {
395-
w.addHookCalls(fn, h1, h2, args, nil)
396-
}
397-
w.line(`}`)
398-
})
399-
})
400-
}
401-
402-
func (w *Writer) addPanicCallback() {
403-
w.block(func() {
404-
w.line("defer func() {")
405-
w.block(func() {
406-
w.line("if e := recover(); e != nil {")
407389
w.block(func() {
408-
w.line(`options.panicCallback(e)`)
390+
w.line("defer func() {")
391+
w.block(func() {
392+
w.line("if e := recover(); e != nil {")
393+
w.block(func() {
394+
w.line(`options.panicCallback(e)`)
395+
})
396+
w.line("}")
397+
})
398+
w.line("}()")
409399
})
410400
w.line("}")
411-
})
412-
w.line("}()")
413-
})
414-
}
415-
416-
func (w *Writer) declareResults(fn *Func) []string {
417-
r1 := w.declare("r")
418-
r2 := w.declare("r")
419-
rs := []string{r1, r2}
420-
w.code("var " + r1 + ", " + r2 + " ")
421-
w.funcResults(fn)
422-
_ = w.bw.WriteByte('\n')
423-
w.atEOL = true
424-
425-
return rs
426-
}
427-
428-
func (w *Writer) addHookCalls(fn *Func, h1, h2 string, args, rs []string) {
429-
for i, h := range []string{h1, h2} {
430-
w.line("if " + h + " != nil {")
431-
w.block(func() {
401+
var (
402+
r1 string
403+
r2 string
404+
rs []string
405+
)
406+
if fn.HasResult() {
407+
r1 = w.declare("r")
408+
r2 = w.declare("r")
409+
rs = []string{r1, r2}
410+
w.code("var " + r1 + ", " + r2 + " ")
411+
w.funcResults(fn)
412+
_ = w.bw.WriteByte('\n')
413+
w.atEOL = true
414+
}
415+
for i, h := range []string{h1, h2} {
416+
w.line("if " + h + " != nil {")
417+
w.block(func() {
418+
if fn.HasResult() {
419+
w.code(rs[i], ` = `) //nolint:scopelint
420+
}
421+
w.code(h) //nolint:scopelint
422+
w.call(args)
423+
})
424+
w.line("}")
425+
}
432426
if fn.HasResult() {
433-
w.code(rs[i], ` = `) //nolint:scopelint
427+
w.code(`return `)
428+
switch x := fn.Result[0].(type) {
429+
case *Func:
430+
w.composeHookCall(x, r1, r2)
431+
case *Trace:
432+
w.line(r1, `.Compose(`, r2, `)`)
433+
default:
434+
panic("unknown result type")
435+
}
434436
}
435-
w.code(h) //nolint:scopelint
436-
w.call(args)
437437
})
438-
w.line("}")
439-
}
440-
}
441-
442-
func (w *Writer) addReturnStatement(fn *Func, rs []string) {
443-
w.code(`return `)
444-
switch x := fn.Result[0].(type) {
445-
case *Func:
446-
w.composeHookCall(x, rs[0], rs[1])
447-
case *Trace:
448-
w.line(rs[0], `.Compose(`, rs[1], `)`)
449-
default:
450-
panic("unknown result type")
451-
}
438+
w.line(`}`)
439+
})
452440
}
453441

454442
func (w *Writer) options(trace *Trace) {

internal/credentials/static.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ func (c *Static) Token(ctx context.Context) (token string, err error) {
8787
fmt.Errorf("dial failed: %w", err),
8888
)
8989
}
90-
defer func() {
91-
_ = cc.Close()
92-
}()
90+
defer cc.Close()
9391

9492
client := Ydb_Auth_V1.NewAuthServiceClient(cc)
9593

internal/value/nullable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func NullableDyNumberValue(v *string) Value {
299299
// Nullable makes optional value from nullable type
300300
// Warning: type interface will be replaced in the future with typed parameters pattern from go1.18
301301
//
302-
//nolint:gocyclo
302+
//nolint:gocyclo, funlen
303303
func Nullable(t types.Type, v interface{}) Value {
304304
switch t {
305305
case types.Bool:

internal/value/value.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func nullValueFromYDB(x *Ydb.Value, t types.Type) (_ Value, ok bool) {
7878
}
7979
}
8080

81+
//nolint:funlen
8182
func primitiveValueFromYDB(t types.Primitive, v *Ydb.Value) (Value, error) {
8283
switch t {
8384
case types.Bool:
@@ -167,6 +168,7 @@ func primitiveValueFromYDB(t types.Primitive, v *Ydb.Value) (Value, error) {
167168
}
168169
}
169170

171+
//nolint:funlen
170172
func fromYDB(t *Ydb.Type, v *Ydb.Value) (Value, error) {
171173
tt := types.TypeFromYDB(t)
172174

@@ -2307,6 +2309,7 @@ func YSONValue(v []byte) ysonValue {
23072309
return v
23082310
}
23092311

2312+
//nolint:funlen
23102313
func zeroPrimitiveValue(t types.Primitive) Value {
23112314
switch t {
23122315
case types.Bool:

retry/sql.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ func WithTxOptions(txOptions *sql.TxOptions) txOptionsOption {
130130
}
131131

132132
// DoTx is a retryer of database/sql transactions with fallbacks on errors
133+
//
134+
//nolint:funlen
133135
func DoTx(ctx context.Context, db *sql.DB, op func(context.Context, *sql.Tx) error, opts ...doTxOption) error {
134136
var (
135137
options = doTxOptions{

0 commit comments

Comments
 (0)