Better detection and error messages for invalid values during `Actor` initialization
- Dominant language
- Python
- Stars
- 611
- Forks
- 211
- PR merge metrics
- No merged PRs in 30d
Description
Better detection and error messages for invalid values during `Actor` initialization would be useful to aid users in debugging.
Expected result:
Better and consistent error messages to aid in debugging and catch obvious invalid values.
Actual result:
The error messages are confusing (for beginner programmers) and inconsistent. And in one case the error is not detected at all.
Here are some examples of invalid `pos` values. Some of these may be easier than others to debug for beginners.
```
alien = Actor('alien', pos=1)
# TypeError: cannot unpack non-iterable int object
```
```
alien = Actor('alien', pos=(0, 1, 2))
# ValueError: too many values to unpack (expected 2)
```
```
alien = Actor('alien', pos=([0], [0]))
# TypeError: unsupported operand type(s) for -: 'list' and 'float'
```
```
alien = Actor('alien', pos=('x', 'y'))
# TypeError: unsupported operand type(s) for -: 'str' and 'float'
```
These invalid `topleft` values are not detected until drawn (while the above `pos` errors are detected when the actor is initialized). They also give different errors than `pos` does when set to the same invalid values.
```
alien = Actor('alien', topleft=([0], [0]))
def draw():
alien.draw()
# TypeError: invalid destination position for blit
```
```
alien = Actor('alien', topleft=('x', 'y'))
def draw():
alien.draw()
# TypeError: invalid destination position for blit
```
This invalid `pos` value is not detected at all.
```
alien = Actor('alien', pos=0)
def draw():
alien.draw()
```
System details:
- os: windows 10 (64bit)
- python: 3.7.2 (64bit)
- pygame: 1.9.4
- pgzero: 1.2 (also master branch at ef963beaa22db89cb011695e96587bb268cbec2a)
- numpy: 1.15.4
Related to #170.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the Actor initialization and drawing paths described in the examples, then compare how pos and topleft values are handled. Reproduce the listed invalid inputs and make validation and error reporting consistent, including detecting invalid values during initialization rather than drawing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100