BurnySc2/python-sc2

Make error message clearer when issueing _do_actions

Opened this issue · 0 comments

In

raise RuntimeError(f"Must target a unit, point or None, found '{target !r}'")
currently only the target is listed, but could also print the ability and units (or unit types) that the command was issued to. This should make it easier to debug the error message, as it only comes up after on_step has been run. The error message only points to the marked line of code, instead of the line where the command was issued to the unit.

Additionally add sanity checks for argument types in

python-sc2/sc2/unit.py

Lines 1472 to 1489 in 40dc00a

if target is None and expected_target not in {1, 5}:
warnings.warn(
f"{self} got {ability} with no target but expected {TARGET_HELPER[expected_target]}",
RuntimeWarning,
stacklevel=2,
)
elif isinstance(target, Point2) and expected_target not in {2, 4, 5}:
warnings.warn(
f"{self} got {ability} with Point2 as target but expected {TARGET_HELPER[expected_target]}",
RuntimeWarning,
stacklevel=2,
)
elif isinstance(target, Unit) and expected_target not in {3, 4}:
warnings.warn(
f"{self} got {ability} with Unit as target but expected {TARGET_HELPER[expected_target]}",
RuntimeWarning,
stacklevel=2,
)