Fix bugs in GetRecord and ListMetadataFormats

Modify BadArgumentException to provide more specific exception message