davydany/sultan

[Improvement] Make the exception dump while invoking run() optional

Opened this issue · 2 comments

N0K0 commented

Hi!

Been using Sultan for a little while now and i've found one part that should be improved.

from api.py -> cmd -> run()

       except Exception as e:
            result = Result(None, commands, self._context, exception=e)
            result.dump_exception()
            if halt_on_nonzero:
                raise e

The dump_exception() should be optional. At the moment i have three instances of Sultan running "inside" each other due to ssh chaining, and as you might understand, the stack dumb turns into a giant mess when a dump is invoked at layer 3 up to layer 1

N0K0 commented

I can come with an PR if you want. Would you like an new parameter, or via the quite flag?

N0K0 commented

Currently working my way around the dump with a monkey patch

def dump_exception_patch(self):
    if not self._exception:
        try:
            raise subprocess.CalledProcessError(
                self.rc, "".join(self._commands), self.stderr
            )
        except subprocess.CalledProcessError as e:
            self._exception = e

        # Removed all log dumping here

        if self._halt_on_nonzero:
            raise self._exception

Result.dump_exception = dump_exception_patch