Skip to content

Commit

Permalink
[TVMC] Treat invalid FILE arguments (apache#9213)
Browse files Browse the repository at this point in the history
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 <gustavo.romero@linaro.org>
  • Loading branch information
gromero authored and ylc committed Jan 7, 2022
1 parent 3f00259 commit 21c6227
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion python/tvm/driver/tvmc/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 21c6227

Please sign in to comment.