Skip to content

Commit

Permalink
Ensure the input file is a JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
gabryelreyes committed Jun 26, 2024
1 parent eaf07d7 commit 761c77f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/pySupersetCli/cmd_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ def _execute(args, superset_client: Superset) -> Ret:

if ("" != args.table) and ("" != args.file) and (None is not superset_client):
try:
with open(args.file, mode="r", encoding="UTF-8") as json_file:
if args.file.endswith(".json") is False:
raise ValueError(
"Invalid file format. Please provide a JSON file.")

with open(args.file, encoding="utf-8") as json_file:
# Input is a dictionary, with keys as index
data_frame = pd.read_json(json_file, orient='index')

Expand Down Expand Up @@ -149,7 +153,7 @@ def _execute(args, superset_client: Superset) -> Ret:
os.remove(_TEMP_FILE_NAME)

except Exception as e: # pylint: disable=broad-except
LOG.error("%s", e)
LOG.error("Exception: %s", e)
return_status = Ret.ERROR_INVALID_ARGUMENTS

return return_status
Expand Down

0 comments on commit 761c77f

Please sign in to comment.