Modify error info

This commit is contained in:
shenwei41 2021-05-11 20:28:08 +08:00
parent e54c810c54
commit cbcaf9b156
2 changed files with 12 additions and 5 deletions

View File

@ -63,7 +63,7 @@ class ExceptionThread(threading.Thread):
self.exception = e
self.exc_traceback = ''.join(traceback.format_exception(*sys.exc_info()))
def check_filename(path):
def check_filename(path, arg_name=""):
"""
check the filename in the path.
@ -77,8 +77,12 @@ def check_filename(path):
Returns:
Bool, whether filename is valid.
"""
if arg_name == "":
arg_name = "File path"
else:
arg_name = "'{}'".format(arg_name)
if not path:
raise ParamValueError('File path is not allowed None or empty!')
raise ParamValueError('{} is not allowed None or empty!'.format(arg_name))
if not isinstance(path, str):
raise ParamValueError("File path: {} is not string.".format(path))
if path.endswith("/"):
@ -113,7 +117,7 @@ def populate_data(raw, blob, columns, blob_fields, schema):
MRMUnsupportedSchemaError: If schema is invalid.
"""
if raw:
# remove dummy fileds
# remove dummy fields
raw = {k: v for k, v in raw.items() if k in schema}
else:
raw = {}

View File

@ -136,6 +136,9 @@ class TFRecordToMR:
else:
if len(val.shape) != 1:
raise ValueError("Parameter len(feature_dict[{}].shape) should be 1.")
if not isinstance(val.shape[0], int):
raise ValueError("Invalid parameter feature_dict, value and type mismatch, " +
"please check item of feature_dict[\"{}\"].".format(key))
if val.shape[0] < 1:
raise ValueError("Parameter feature_dict[{}].shape[0] should > 0".format(key))
if val.dtype == self.tf.string:
@ -149,11 +152,11 @@ class TFRecordToMR:
"""Validation check for inputs of init method"""
if not isinstance(source, str):
raise ValueError("Parameter source must be string.")
check_filename(source)
check_filename(source, "source")
if not isinstance(destination, str):
raise ValueError("Parameter destination must be string.")
check_filename(destination)
check_filename(destination, "destination")
if feature_dict is None or not isinstance(feature_dict, dict):
raise ValueError("Parameter feature_dict is None or not dict.")