Skip to content

Commit

Permalink
Merge pull request #779 from armintaenzertng/issue-775-catch-json-dec…
Browse files Browse the repository at this point in the history
…ode-error

[issue-775] catch decoding errors while parsing using the cli tool
  • Loading branch information
maxhbr authored Apr 14, 2024
2 parents 2dacc42 + a1ceee6 commit 552940a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/spdx_tools/spdx/clitools/pyspdxtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
# limitations under the License.
import logging
import sys
from json import JSONDecodeError
from xml.parsers.expat import ExpatError
from xml.sax import SAXParseException

import click
from beartype.typing import List
from yaml.scanner import ScannerError

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

except JSONDecodeError as err:
logging.error(f"Invalid JSON provided: {err.args[0]}")
sys.exit(1)

except ScannerError as err:
logging.error("Invalid YAML provided: " + "\n".join([str(arg) for arg in err.args]))
sys.exit(1)

except ExpatError as err:
logging.error(f"Invalid XML provided: {err.args[0]}")
sys.exit(1)

except SAXParseException as err:
logging.error(f"Invalid RDF-XML provided: {str(err)}")
sys.exit(1)

except FileNotFoundError as err:
logging.error(f"{err.strerror}: {err.filename}")
sys.exit(1)
Expand Down

0 comments on commit 552940a

Please sign in to comment.