Skip to content

Commit 8279a3e

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 8279a3e

File tree

5 files changed

+30
-25
lines changed

5 files changed

+30
-25
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func RPCErr(req *lnrpc.RPCMiddlewareRequest,
5454
err error) (*lnrpc.RPCMiddlewareResponse, error) {
5555

5656
if err != nil {
57-
return RPCErrString(req, err.Error())
57+
return RPCErrString(req, err.Error(), nil)
5858
}
5959

6060
return RPCOk(req)

status/manager.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,24 +258,34 @@ func (s *Manager) SetStopped(name string) {
258258
//
259259
// NOTE: This will silently fail if the referenced sub-server has not yet been
260260
// registered.
261-
func (s *Manager) SetErrored(name string, errStr string,
262-
params ...interface{}) {
263-
261+
func (s *Manager) SetErrored(name string, errStr string) {
264262
s.mu.Lock()
265263
defer s.mu.Unlock()
266264

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

271267
ss, ok := s.subServers[name]
272268
if !ok {
273269
return
274270
}
275271

276-
log.Errorf("could not start the %s sub-server: %s", name, err)
272+
log.Errorf("could not start the %s sub-server: %s", name, errStr)
277273

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

terminal.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ func (g *LightningTerminal) Run(ctx context.Context) error {
402402
// could not start or LND could not start or be connected to.
403403
startErr := g.start(ctx)
404404
if startErr != nil {
405-
g.statusMgr.SetErrored(
405+
g.statusMgr.SetErroredf(
406406
subservers.LIT, "could not start Lit: %v", startErr,
407407
)
408408
}
@@ -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,
@@ -610,7 +607,7 @@ func (g *LightningTerminal) start(ctx context.Context) error {
610607
// Connect to LND.
611608
g.lndConn, err = connectLND(g.cfg, bufRpcListener)
612609
if err != nil {
613-
g.statusMgr.SetErrored(
610+
g.statusMgr.SetErroredf(
614611
subservers.LND, "could not connect to LND: %v", err,
615612
)
616613

@@ -723,7 +720,7 @@ func (g *LightningTerminal) start(ctx context.Context) error {
723720
// servers, as the setup will be fast.
724721
err = g.setupBasicLNDClient(ctx, lndQuit)
725722
if err != nil {
726-
g.statusMgr.SetErrored(
723+
g.statusMgr.SetErroredf(
727724
subservers.LND,
728725
"could not to set up a basic LND client: %v", err,
729726
)
@@ -756,7 +753,7 @@ func (g *LightningTerminal) start(ctx context.Context) error {
756753
// needed for LiT to be fully started.
757754
err = g.setupFullLNDClient(ctx, lndQuit)
758755
if err != nil {
759-
g.statusMgr.SetErrored(
756+
g.statusMgr.SetErroredf(
760757
subservers.LND,
761758
"could not to set up a full LND client: %v", err,
762759
)
@@ -880,7 +877,7 @@ func (g *LightningTerminal) setupBasicLNDClient(ctx context.Context,
880877
break
881878
}
882879

883-
g.statusMgr.SetErrored(
880+
g.statusMgr.SetErroredf(
884881
subservers.LIT,
885882
"Error when setting up basic LND Client: %v", err,
886883
)
@@ -962,7 +959,7 @@ func (g *LightningTerminal) setupFullLNDClient(ctx context.Context,
962959
break
963960
}
964961

965-
g.statusMgr.SetErrored(
962+
g.statusMgr.SetErroredf(
966963
subservers.LIT,
967964
"Error when creating LND Services client: %v",
968965
err,

0 commit comments

Comments
 (0)