diff options
| -rw-r--r-- | tools/mpremote/mpremote/commands.py | 8 | ||||
| -rw-r--r-- | tools/mpremote/mpremote/transport.py | 16 |
2 files changed, 6 insertions, 18 deletions
diff --git a/tools/mpremote/mpremote/commands.py b/tools/mpremote/mpremote/commands.py index 1e13b33af..b1e5d3c7e 100644 --- a/tools/mpremote/mpremote/commands.py +++ b/tools/mpremote/mpremote/commands.py @@ -393,12 +393,8 @@ def do_filesystem(state, args): ) else: do_filesystem_cp(state, path, cp_dest, len(paths) > 1, not args.force) - except FileNotFoundError as er: - raise CommandError("{}: {}: No such file or directory.".format(command, er.args[0])) - except IsADirectoryError as er: - raise CommandError("{}: {}: Is a directory.".format(command, er.args[0])) - except FileExistsError as er: - raise CommandError("{}: {}: File exists.".format(command, er.args[0])) + except OSError as er: + raise CommandError("{}: {}: {}.".format(command, er.strerror, os.strerror(er.errno))) except TransportError as er: raise CommandError("Error with transport:\n{}".format(er.args[0])) diff --git a/tools/mpremote/mpremote/transport.py b/tools/mpremote/mpremote/transport.py index 8d30c7f51..df8ef209a 100644 --- a/tools/mpremote/mpremote/transport.py +++ b/tools/mpremote/mpremote/transport.py @@ -55,18 +55,10 @@ listdir_result = namedtuple("dir_result", ["name", "st_mode", "st_ino", "st_size # Takes a Transport error (containing the text of an OSError traceback) and # raises it as the corresponding OSError-derived exception. def _convert_filesystem_error(e, info): - if "OSError" in e.error_output and "ENOENT" in e.error_output: - return FileNotFoundError(info) - if "OSError" in e.error_output and "EISDIR" in e.error_output: - return IsADirectoryError(info) - if "OSError" in e.error_output and "EEXIST" in e.error_output: - return FileExistsError(info) - if "OSError" in e.error_output and "ENODEV" in e.error_output: - return FileNotFoundError(info) - if "OSError" in e.error_output and "EINVAL" in e.error_output: - return OSError(errno.EINVAL, info) - if "OSError" in e.error_output and "EPERM" in e.error_output: - return OSError(errno.EPERM, info) + if "OSError" in e.error_output: + for code, estr in errno.errorcode.items(): + if estr in e.error_output: + return OSError(code, info) return e |
