Merge "Better exception messages"

This commit is contained in:
Jenkins 2016-11-21 23:43:59 +00:00 committed by Gerrit Code Review
commit 8757ff2234
3 changed files with 40 additions and 17 deletions

View File

@ -165,26 +165,40 @@ def list_cli_opts():
def list_syntribos_opts():
def wrap_try_except(func):
def wrap(*args):
try:
func(*args)
except IOError:
print("\nCan't open a file or directory specified in the "
"config file under the section `[syntribos]`; verify "
"if the path exists.\nFor more information please refer "
"the debug logs.")
exit(1)
return wrap
return [
cfg.StrOpt("endpoint", default="",
sample_default="http://localhost/app",
help="The target host to be tested"),
cfg.Opt("templates", type=ContentType("r", 0), default="",
cfg.Opt("templates", type=wrap_try_except(ContentType("r", 0)),
default="",
sample_default="~/.syntribos/templates",
help="A directory of template files, or a single template "
"file, to test on the target API"),
cfg.StrOpt("payloads", default="",
sample_default="~/.syntribos/data",
help="The location where we can find syntribos' payloads"),
help="The location where we can find syntribos'"
"payloads"),
cfg.MultiStrOpt("exclude_results",
default=[""],
sample_default=["500_errors", "length_diff"],
help="Defect types to exclude from the "
"results output"),
cfg.Opt("custom_root", type=ExistingDirType(), short="c",
cfg.Opt("custom_root", type=wrap_try_except(ExistingDirType()),
short="c",
sample_default="/your/custom/root",
help="The root directory where the subfolders that make up "
"syntribos' environment (logs, templates, payloads, "
help="The root directory where the subfolders that make up"
" syntribos' environment (logs, templates, payloads, "
"configuration files, etc.)"),
]

View File

@ -168,18 +168,22 @@ class Runner(object):
cls.setup_config()
else:
cls.setup_config(use_file=True)
try:
if CONF.sub_command.name == "init":
ENV.initialize_syntribos_env()
exit(0)
if CONF.sub_command.name == "init":
ENV.initialize_syntribos_env()
exit(0)
elif CONF.sub_command.name == "list_tests":
cls.list_tests()
exit(0)
elif CONF.sub_command.name == "list_tests":
cls.list_tests()
exit(0)
elif CONF.sub_command.name == "download":
ENV.download_wrapper()
exit(0)
elif CONF.sub_command.name == "download":
ENV.download_wrapper()
exit(0)
except AttributeError:
print("Not able to run the requested sub command, please check "
"the debug logs for more information, exiting...")
exit(1)
if not ENV.is_syntribos_initialized():
print("Syntribos was not initialized. Please run the 'init' "
@ -206,7 +210,12 @@ class Runner(object):
print("Attempting to download templates from {}".format(
CONF.remote.templates_uri))
templates_path = remotes.get(CONF.remote.templates_uri)
templates_dir = ContentType("r", 0)(templates_path)
try:
templates_dir = ContentType("r", 0)(templates_path)
except IOError:
print("Not able to open `{}`; "
"please verify path, exiting...".format(templates_path))
exit(1)
print("\nPress Ctrl-C to pause or exit...\n")
for file_path, req_str in templates_dir:

View File

@ -21,7 +21,7 @@ class ExistingPathType(object):
msg = ("\nCan't open '{filename}'; not a readable file or dir."
"\nPlease enter a valid file or dir location.{exception}"
).format(filename=filename,
exception="\nEXCEPTION: {exc}\n".format(exc=exc))
exception="\nException: {exc}\n".format(exc=exc))
raise IOError(msg)
def __call__(self, string):