From 41998b964b16ee831cf284cf3238781daacbc0b8 Mon Sep 17 00:00:00 2001 From: Gustavo Romero Date: Wed, 6 Oct 2021 17:58:42 +0000 Subject: [PATCH] [TVMC] Treat invalid FILE arguments Currently if an invalid FILE argument is passed to 'tvmc run' the user will catch a traceback because exceptions are not treated, for instance: $ tvmc run /tmp/nonexistingfile will throw a FileNotFoundError trace. This commit catches the possible exceptions that can happen when an invalid FILE argument is used and convert them to better messages for the user so the invalid FILE can be easily spotted. Signed-off-by: Gustavo Romero --- python/tvm/driver/tvmc/runner.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/python/tvm/driver/tvmc/runner.py b/python/tvm/driver/tvmc/runner.py index 5a15d228803d..659df7ceef33 100644 --- a/python/tvm/driver/tvmc/runner.py +++ b/python/tvm/driver/tvmc/runner.py @@ -20,6 +20,7 @@ import json import logging from typing import Dict, List, Optional, Union +from tarfile import ReadError import numpy as np import tvm @@ -115,7 +116,14 @@ def drive_run(args): except IOError as ex: raise TVMCException("Error loading inputs file: %s" % ex) - tvmc_package = TVMCPackage(package_path=args.FILE) + try: + tvmc_package = TVMCPackage(package_path=args.FILE) + except IsADirectoryError: + raise TVMCException(f"File {args.FILE} must be an archive, not a directory.") + except FileNotFoundError: + raise TVMCException(f"File {args.FILE} does not exist.") + except ReadError: + raise TVMCException(f"Could not read model from archive {args.FILE}!") result = run_module( tvmc_package,