Skip to content

Commit bfcf0a0

Browse files
committed
multi: prepare for new non-constant string rule
In preparation for the next commit which bumps golang to a newer version, we want to make some code changes that would otherwise render some log-related calls problematic. With go1.24 a new govet rule was added that disallows non-constant strings (i.e including a tag like "%s") in calls to printf. See more in the related issue golang/go#60529.
1 parent bce4c04 commit bfcf0a0

File tree

5 files changed

+31
-16
lines changed

5 files changed

+31
-16
lines changed

itest/network_harness.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,10 @@ out:
270270

271271
n.EnsureConnected(t, n.Alice, n.Bob)
272272

273-
logLine := fmt.Sprintf(
274-
"STARTING ============ %v ============\n", testCase,
275-
)
273+
logLine := "STARTING ============ %v ============\n"
276274

277-
n.Alice.AddToLog(logLine)
278-
n.Bob.AddToLog(logLine)
275+
n.Alice.AddToLog(logLine, testCase)
276+
n.Bob.AddToLog(logLine, testCase)
279277

280278
return nil
281279
}

rpc_proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ func (p *rpcProxy) makeDirector(allowLitRPC bool) func(ctx context.Context,
364364
// gRPC server.
365365
handled, conn, err := p.subServerMgr.GetRemoteConn(requestURI)
366366
if err != nil {
367-
return outCtx, nil, status.Errorf(
367+
return outCtx, nil, status.Error(
368368
codes.Unavailable, err.Error(),
369369
)
370370
}

rpcmiddleware/proto.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,12 @@ func RPCErrString(req *lnrpc.RPCMiddlewareRequest, format string,
7676
},
7777
}
7878

79+
if len(args) > 0 {
80+
format = fmt.Sprintf(format, args...)
81+
}
82+
7983
if format != "" {
80-
feedback.Error = fmt.Sprintf(format, args...)
84+
feedback.Error = format
8185
}
8286

8387
return resp, nil

status/manager.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,34 @@ func (s *Manager) SetErrored(name string, errStr string,
264264
s.mu.Lock()
265265
defer s.mu.Unlock()
266266

267-
err := fmt.Sprintf(errStr, params...)
268-
269-
log.Debugf("Setting the %s sub-server as errored: %s", name, err)
267+
log.Debugf("Setting the %s sub-server as errored: %s", name, errStr)
270268

271269
ss, ok := s.subServers[name]
272270
if !ok {
273271
return
274272
}
275273

276-
log.Errorf("could not start the %s sub-server: %s", name, err)
274+
if len(params) > 0 {
275+
errStr = fmt.Sprintf(errStr, params...)
276+
}
277+
278+
log.Errorf("could not start the %s sub-server: %s", name, errStr)
277279

278280
ss.running = false
279-
ss.err = err
281+
ss.err = errStr
280282
ss.customStatus = ""
281283
}
284+
285+
// SetErroredf can be used to set the status of a sub-server as not Running and
286+
// also set an error message for the sub-server. This function can also accept
287+
// non-constant strings which may contain extra arguments.
288+
//
289+
// NOTE: This will silently fail if the referenced sub-server has not yet been
290+
// registered.
291+
// func (s *Manager) SetErroredf(name string, errStr string,
292+
// params ...interface{}) {
293+
294+
// errStr = fmt.Sprintf(errStr, params...)
295+
296+
// s.SetErrored(name, errStr)
297+
// }

terminal.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,7 @@ func (g *LightningTerminal) start(ctx context.Context) error {
431431
var err error
432432

433433
accountServiceErrCallback := func(err error) {
434-
g.statusMgr.SetErrored(
435-
subservers.ACCOUNTS,
436-
err.Error(),
437-
)
434+
g.statusMgr.SetErrored(subservers.ACCOUNTS, err.Error())
438435

439436
log.Errorf("Error thrown in the accounts service, keeping "+
440437
"litd running: %v", err,

0 commit comments

Comments
 (0)