Skip to content

Commit b0a2ec0

Browse files
committed
fix(cmd): nil pointer dereference in PrintProgressBarsOnEvents
We now call on `o.Instance()` to get access to the underlying dataset methods (at the lib level). However, this leads to a `nil pointer dereference` error, when we use the CLI to interact with the qri node over http rpc. `o.Instance()` first calls `o.Init()`, which creates and sets up an instance if we don't currently have one using `lib.NewInstance`. When using the CLI to interact with a qri node via http rpc, however, `lib.NewInstance` returns early after setting up an `HTTPClient` in `inst.http`, so we route any CLI calls to the running qri node. `o.Init()` continues, but expects an instance with a `bus`, so it can pass the bus to `PrintProgressBarOnEvents`, which gives feedback to the user via progress bars. This bus is nil, so when `PrintProgressBarOnEvents` tries to subscribe to events on the bus, we get the error in question. Because we will probably want to give users progress via http rpc at some point, rather than disabling this behavior via rpc, the current fix just guards against a nil bus before attempting to subscribe to any events.
1 parent b1fab21 commit b0a2ec0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

cmd/print.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ func PrintProgressBarsOnEvents(w io.Writer, bus event.Bus) {
244244
p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(w))
245245
progress := map[string]*mpb.Bar{}
246246

247+
if bus == nil {
248+
log.Errorf("event bus is nil")
249+
return
250+
}
247251
// wire up a subscription to print download progress to streams
248252
bus.SubscribeTypes(func(_ context.Context, e event.Event) error {
249253
lock.Lock()

cmd/qri.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ func (o *QriOptions) Init() (err error) {
167167
// being false also disables progress bars, which may be what we want (ahem: TTY
168168
// detection), but even if so, isn't the right use of this variable name
169169
if shouldColorOutput {
170+
// TODO(ramfox): we guard for a nil bus in `PrintProgressBarsOnEvents`
171+
// but noting here that no requests that go through http rpc will have
172+
// a working bus, so we won't get any progress bars when working over
173+
// http rpc until this is adjusted (once we get the events "rpc-ified")
170174
PrintProgressBarsOnEvents(o.IOStreams.ErrOut, o.inst.Bus())
171175
}
172176

0 commit comments

Comments
 (0)