Some of the goto err clauses do not set the error code. It seems better to fall back on INVALIDDATA instead of adding it everywhere explicitly.