Skip to content

Commit

Permalink
fix nil interface bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirms committed Dec 14, 2020
1 parent bf8a410 commit 6a61fad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions ingest/ledgerbackend/captive_core_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,13 @@ func (c *CaptiveStellarCore) openOfflineReplaySubprocess(from, to uint32) error
to = latestCheckpointSequence
}

c.stellarCoreRunner, err = c.stellarCoreRunnerFactory(stellarCoreRunnerModeOffline)
if err != nil {
var runner stellarCoreRunnerInterface
if runner, err = c.stellarCoreRunnerFactory(stellarCoreRunnerModeOffline); err != nil {
return errors.Wrap(err, "error creating stellar-core runner")
} else {
// only assign c.stellarCoreRunner if runner is not nil to avoid nil interface check
// see https://golang.org/doc/faq#nil_error
c.stellarCoreRunner = runner
}

err = c.stellarCoreRunner.catchup(from, to)
Expand Down Expand Up @@ -231,9 +235,13 @@ func (c *CaptiveStellarCore) openOnlineReplaySubprocess(from uint32) error {
)
}

c.stellarCoreRunner, err = c.stellarCoreRunnerFactory(stellarCoreRunnerModeOnline)
if err != nil {
var runner stellarCoreRunnerInterface
if runner, err = c.stellarCoreRunnerFactory(stellarCoreRunnerModeOnline); err != nil {
return errors.Wrap(err, "error creating stellar-core runner")
} else {
// only assign c.stellarCoreRunner if runner is not nil to avoid nil interface check
// see https://golang.org/doc/faq#nil_error
c.stellarCoreRunner = runner
}

runFrom, ledgerHash, nextLedger, err := c.runFromParams(from)
Expand Down
2 changes: 1 addition & 1 deletion ingest/ledgerbackend/captive_core_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ func TestGetLatestLedgerSequence(t *testing.T) {
err := captiveBackend.PrepareRange(UnboundedRange(64))
assert.NoError(t, err)

// To prevent flaky test runs handleExit for channel to fill.
// To prevent flaky test runs wait for channel to fill.
waitForBufferToFill(&captiveBackend)

latest, err := captiveBackend.GetLatestLedgerSequence()
Expand Down

0 comments on commit 6a61fad

Please sign in to comment.