[game-data-packager] 02/08: better assertions
Simon McVittie
smcv at debian.org
Thu Jan 15 14:20:29 UTC 2015
On 15/01/15 14:07, Peter Pentchev wrote:
> On Wed, Jan 14, 2015 at 12:38:17AM +0000, Simon McVittie wrote:
>> - assert wanted.md5 is None
>> + assert wanted.md5 is None, wanted.name
>
> Hmm, those don't look optimal to me :) What do you think about
> the attached trivial patch?
>
> - assert wanted.md5 is None, wanted.name
> + assert wanted.md5 is None, wanted.md5
I think "no". The use-case here is for if you write the YAML description
of a game, but get it wrong, and it said something like:
files:
main/sp_pak1.pk3:
alternatives: # this means: installing either _en or _fr is fine
- main/sp_pak1.pk3_en
- main/sp_pak1.pk3_fr
md5: deadbeef12345678
That's clearly nonsense: there's no point in having a set of
alternatives if all the files actually contain the same bytes, but if
they aren't all the same content, they can't possibly all have the same
md5 (assuming no deliberate collisions). Hence it's an error. It's an
AssertionError because I was too lazy to write "error parsing rtcw.yaml:
main/sp_pak1.pk3 has alternatives [..._en, ..._fr] but they can't both
have md5sum deadbeef12345678".
Having the assertion failure message be "wanted.md5 is None" is pretty
unhelpful, so I provided the optional second argument. But the md5 is
not very helpful as the second argument, because a traceback ending with
at line 666:
assert wanted.md5 is None, wanted.md5
AssertionError: deadbeef12345678
doesn't actually tell you what "wanted" is. Using wanted.name turns it into
at line 666:
assert wanted.md5 is None, wanted.name
AssertionError: main/sp_pak1.pk3
and now you know "aha, main/sp_pak1.pk3 should not have a md5" and can
go looking for it.
If you want to do a patch that turns this into something more
descriptive like "ValueError: error parsing %s: %s has alternatives %r
but they can't both have %ssum %s" or something, go for it, but please
don't remove the hint that tells the developer where they should be
looking for their error :-)
S
More information about the Pkg-games-devel
mailing list