Skip to content

Commit

Permalink
loader: require .json extension for JSON files
Browse files Browse the repository at this point in the history
Trying to parse every file other than *.yml as JSON file isn't the best
idea. It wastes time on trying to parse non-template files. It produces
warnings like "json Loader Failed to load (...)template" for files that
were never meant to be templates. It's a bad pracice in general.

Check for file extension before using json.loads().

Fixes: 0d2d16c ("Native JSON Template Support")
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  • Loading branch information
Rafał Miłecki authored and bosd committed Nov 2, 2023
1 parent 963d514 commit edf3183
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/invoice2data/extract/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ def read_templates(folder=None):
except YAMLError as error:
logger.warning("Failed to load %s template:\n%s", name, error)
continue
else:
elif name.endswith(".json"):
try:
tpl = json.loads(template_file.read())
except ValueError as error:
logger.warning("json Loader Failed to load %s template:\n%s", name, error)
continue
else:
continue
tpl["template_name"] = name

# Test if all required fields are in template
Expand Down

0 comments on commit edf3183

Please sign in to comment.