Skip to content

Feature Request: Version of LongRunning that returns TaskError on non zero return code? #453

@eddieparker

Description

@eddieparker

I'd love if there was a version of doit.tools.LongRunning that had it return TaskError if return code was non zero. I tend to use this for a light build system for tasks that have dependencies, and having it not stop at the first error requires a bunch of scrolling and buries problems.

I tend to unroll it in my own dodo.py scripts, but it'd be nice if it was inbuilt. I ended up hacking my own locally in my dodo.py and it works quite nicely:

class LongRunningTask(doit.tools.CmdAction):
	' Run a command and wait for it to finish, and fail if it fails.'

	def execute(self, out=None, err=None):
		action = self.expand_action()
		process = subprocess.Popen(
			action, shell=self.shell, stdout=out, stderr=err, **self.pkwargs,)
		try:
			return_value = process.wait()
		
			if return_value != 0:
				return doit.exceptions.TaskError(f'Command failed with return code {return_value}')

		except KeyboardInterrupt:
			# normal way to stop interactive process
			pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions