Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch UnicodeDecodeError in lobster-json #103

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions lobster/tools/json/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,11 @@ def get_item(root, path, required):
elif required:
raise Malformed_Input("object does not contain %s" % field,
root)
else:
return None
return None

elif required:
raise Malformed_Input("not an object", root)

else:
return None
return None


def syn_test_name(file_name):
Expand Down Expand Up @@ -107,15 +104,15 @@ def process_tool_options(self, options, work_list):

@classmethod
def process(cls, options, file_name):
with open(file_name, "r", encoding="UTF-8") as fd:
data = json.load(fd)

# First we follow the test-list items to get the actual data
# we're interested in.
try:
with open(file_name, "r", encoding="UTF-8") as fd:
data = json.load(fd)
data = get_item(root = data,
path = options.test_list,
required = True)
except UnicodeDecodeError as decode_error:
print("%s: File is not encoded in utf-8: %s" % (file_name, decode_error))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I observed that the old string formatting method is used rather than f-strings, is there any specific reason due to which it is preferred?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there is no particular reason. I just used it because it is used everywhere else, to stay consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something we should address in the coding guideline #88

return False, []
except Malformed_Input as err:
pprint(err.data)
print("%s: malformed input: %s" % (file_name, err.msg))
Expand Down
Loading