Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
Changes
With cobra, when you define a
PersistentPreRun
in a child command, you overwrite all the command's parentsPersistentPreRun
cobra issue. When introducing telemetry, we used thePersistentPreRun
to send the events, this made therunner
commands not call thePersistentPreRun
incmd/runner/runner.go
which defines theopts.r
value. In the children commands theopts.r
wasnil
, thus causing nil pointer deference panic.This PR makes the
runner
command use thePreRunE
to send their telemetry events to avoid overwriting the parent'sPersistentPreRun
.Rationale
This PR is here in reaction to this CLI telemetry retintroduction. This feature made the runner test crash because it was introducing a nil pointer dereference panic like explained in the
Changes
part. The feature was then reverted. This PR aims at reintroducing the feature with the necessary fix.Note to the reviewer: it is greatly advised not to look at the first commit as it is a revert commit. For more information about this commit content do look into the original PR
Considerations
About the decision of the fix, two possibilities were considered: wrapping the
PreRunE
that was already used by all the commands to make it send the telemetry events or send the telemetry event directly in theRun
of every command. The direction of thePreRunE
was selected because it was easier to implement, more generic and thus would be less likely to be forgotten in the case of the addition of other commands