Check return code of dict_addattr, and use correct argument order

and print a useful error message