Skip to content

Commit

Permalink
Merge pull request #198 from bjoernricks/gvm-cli-error-reporting
Browse files Browse the repository at this point in the history
Gvm cli error reporting
  • Loading branch information
bjoernricks committed Jun 14, 2019
2 parents 8404d43 + 5871d86 commit c280276
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -21,6 +21,7 @@ $ cd gvm-tools && git log
- Added a new console line interface `gvm-script` for only running GMP and OSP
scripts without opening a python shell [PR 152](https://github.com/greenbone/gvm-tools/pull/152)
- Forbid to run any gvm-tools cli as root user [PR 183](https://github.com/greenbone/gvm-tools/pull/183)
- Added error message if invalid XML is passed to `gvm-cli` [PR 198](https://github.com/greenbone/gvm-tools/pull/198)

### Changed
- Improved error messages if unix socket could not be found [PR 78](https://github.com/greenbone/python-gvm/pull/78)
Expand Down
12 changes: 10 additions & 2 deletions gvmtools/cli.py
Expand Up @@ -20,8 +20,10 @@
import logging
import sys

from gvm.errors import GvmError
from gvm.protocols.latest import Gmp, Osp
from gvm.transforms import CheckCommandTransform
from gvm.xml import validate_xml_string

from gvmtools.helper import do_not_run_as_root
from gvmtools.parser import create_parser, create_connection, PROTOCOL_OSP
Expand Down Expand Up @@ -79,13 +81,19 @@ def main():
try:
xml = _load_infile(args.infile)
except IOError as e:
print(e)
print(e, file=sys.stderr)
sys.exit(1)

# If no command was given, program asks for one
if len(xml) == 0:
xml = input()

try:
validate_xml_string(xml)
except GvmError as e:
print(e, file=sys.stderr)
sys.exit(1)

connection = create_connection(**vars(args))

if args.raw:
Expand All @@ -112,7 +120,7 @@ def main():

print(result)
except Exception as e: # pylint: disable=broad-except
print(e)
print(e, file=sys.stderr)
sys.exit(1)

protocol.disconnect()
Expand Down

0 comments on commit c280276

Please sign in to comment.