UNCLASSIFIED - NO CUI

Skip to content

log: refactor HandleError to not panic

Daniel Dides requested to merge dd/174-client-functions-errors into main

General MR

Summary

Update HandleError in logging client functions to no longer panic but rather use os.Exit(1). Also change cobra.CheckErr invocation to use our new HandleError instead.

To make testing easier, HandleError now takes an optional function called exitFunc. For real-world usage this is just os.exit, but that allows us to inject custom behaviors in for testing.

Cannot be merged until all other tickets are complete as the unit tests will not pass. Many unit tests check for a assert.Panics() which will no longer be valid once this is merged, but checking for os.Exit(1) calls is not required either as the calls to HandleError should be removed ultimately.

All other tickets are complete, ready to merge.

Relevant logs/screenshots

Showing new logger catching the error:

danieldides@BPH-MAC14 ~/P/b/p/bbctl (dd/174-client-functions-errors)> bbctl version
bbctl client version 0.7.3
time=2024-07-15T15:46:36.586-05:00 level=INFO msg="ERROR error encountered during execution: stat /Users/danieldides/.kube/config: no such file or directory"

Linked Issue

closes #174 (comment 2309718)

Upgrade Notices

N/A

Edited by Daniel Dides

Merge request reports