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

[issue-775] catch decoding errors while parsing using the cli tool #779

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Changes from all commits
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
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
Loading