fix: collect exceptions on task errors

When async tasks fail, all exceptions need to be collected to not get
subsequent exceptions about invalid future states. This is achieved by
gathering the task results, instead of just waiting for them. By
gathering the results, also user-requested cancellation (e.g. via
ctrl-c) works without throwing tons of additional exceptions.
Since ac437308 we more likely run into that case, which unvealed the bug.

By properly handling the exception, a TaskResultError is returned
instead of the underlying CommandExecError. This change is reflected in
the corresponding unit test.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Felix Moessbauer
2023-05-18 09:15:06 +02:00
committed by Jan Kiszka
parent d2ecff4243
commit ecd670e9ae
3 changed files with 18 additions and 13 deletions

View File

@@ -28,7 +28,7 @@ import json
import yaml
import pytest
from kas import kas
from kas.kasusererror import CommandExecError
from kas.libkas import TaskExecError
def test_for_all_repos(changedir, tmpdir):
@@ -67,7 +67,7 @@ def test_invalid_checkout(changedir, tmpdir, capsys):
tdir = str(tmpdir / 'test_commands')
shutil.copytree('tests/test_commands', tdir)
os.chdir(tdir)
with pytest.raises(CommandExecError):
with pytest.raises(TaskExecError):
kas.kas(['checkout', 'test-invalid.yml'])