Skip to content

Commit 2596548

Browse files
committed
Return errors with result instead of raising
This adds the `raise_on_errors` parameter to the `parse_mod_info` function. This parameter is True by default so that the default behaviour does not change. If the parameter is set to False, the function will return both data and errors. This is necessary because the marshmallow schema returns errors on some conditions that do not warrant raising an exception, e.g. when the mod_info contains an empty string in `url`. Fixes #31
1 parent e7c3d6c commit 2596548

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

faf/tools/fa/mods.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
logger = logging.getLogger(__name__)
1414

1515

16-
def parse_mod_info(zip_file_or_folder):
16+
def parse_mod_info(zip_file_or_folder, raise_on_errors=True):
1717
"""
1818
Returns a broad description of the mod, has the form:
1919
{
@@ -27,6 +27,7 @@ def parse_mod_info(zip_file_or_folder):
2727
}
2828
2929
:param zip_file_or_folder: the zip file or folder to parse
30+
:param raise_on_errors: raise ValueError if the parser has validation errors.
3031
"""
3132
path = Path(zip_file_or_folder)
3233

@@ -48,10 +49,13 @@ def parse_mod_info(zip_file_or_folder):
4849
raise ValueError("Not a directory nor a file: " + str(zip_file_or_folder))
4950

5051
data, errors = ModInfoSchema().load(dict(lua_data))
51-
if errors:
52-
raise ValueError(errors)
53-
54-
return data
52+
if raise_on_errors:
53+
if errors:
54+
raise ValueError(errors)
55+
else:
56+
return data
57+
else:
58+
return data, errors
5559

5660

5761
def read_mod_info(file):

0 commit comments

Comments
 (0)