Skip to content

Commit a1ceee6

Browse files
[issue-775] catch decoding errors while parsing using the cli tool
Signed-off-by: Armin Tänzer <[email protected]>
1 parent 2dacc42 commit a1ceee6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/spdx_tools/spdx/clitools/pyspdxtools.py

+20
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
# limitations under the License.
1515
import logging
1616
import sys
17+
from json import JSONDecodeError
18+
from xml.parsers.expat import ExpatError
19+
from xml.sax import SAXParseException
1720

1821
import click
1922
from beartype.typing import List
23+
from yaml.scanner import ScannerError
2024

2125
from spdx_tools.spdx.graph_generation import export_graph_from_document
2226
from spdx_tools.spdx.model import Document
@@ -113,6 +117,22 @@ def main(infile: str, outfile: str, version: str, novalidation: bool, graph: boo
113117
logging.error(log_string)
114118
sys.exit(1)
115119

120+
except JSONDecodeError as err:
121+
logging.error(f"Invalid JSON provided: {err.args[0]}")
122+
sys.exit(1)
123+
124+
except ScannerError as err:
125+
logging.error("Invalid YAML provided: " + "\n".join([str(arg) for arg in err.args]))
126+
sys.exit(1)
127+
128+
except ExpatError as err:
129+
logging.error(f"Invalid XML provided: {err.args[0]}")
130+
sys.exit(1)
131+
132+
except SAXParseException as err:
133+
logging.error(f"Invalid RDF-XML provided: {str(err)}")
134+
sys.exit(1)
135+
116136
except FileNotFoundError as err:
117137
logging.error(f"{err.strerror}: {err.filename}")
118138
sys.exit(1)

0 commit comments

Comments
 (0)