Skip to content

Resolve "PostRun function in cli does not get called if an error is thrown"

Update all CLI commands to use Run (no error returning) instead of RunE (run with returning errors), since we already had an error logging through pterm. Prompt mode does check now for suggestions if the last cached suggestion is the right one for the current command.


For the prompt mode it is necessary to reset some variables if a command is executed. For this use case cobras PostRun function is used. But this function does not get called if the commands RunE function returns an error. Since we already inform the user through pterm about errors in the CLI it is possible to switch to the Run function.

This MR also addresses another bug within the prompt mode of the CLI. Copy pasting, or failed commands withing the CLI could result in wrong suggestions provided. This was caused through improper resetting of the suggestion cache. This has been fixed with this MR aswell.

Related Issue

Related to #309

Motivation and Context

Improves the overall usage of the CLI, since in a lot of cases a restart of the CLI was required.

How Has This Been Tested?

If tested the most common sources of error, like e.g.:

  • copy pasting of CLI commands
  • using CTRL-C

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)


  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
Edited by Malte Bauch

Merge request reports