@@ -83,26 +83,26 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
83
83
84
84
exit_status = process .returncode
85
85
86
- if encoding :
87
- result = result .decode (encoding )
88
- error = error .decode (encoding )
89
-
90
- if expect_error :
91
- raise Exception (result , error )
86
+ assert type (result ) == bytes # noqa: E721
87
+ assert type (error ) == bytes # noqa: E721
92
88
93
89
if not error :
94
- error_found = 0
90
+ error_found = False
95
91
else :
96
- error = normalize_error (error )
97
92
error_found = exit_status != 0 or any (
98
- marker in error for marker in ['error' , 'Permission denied' , 'fatal' , 'No such file or directory' ]
93
+ marker in error for marker in [b 'error' , b 'Permission denied' , b 'fatal' , b 'No such file or directory' ]
99
94
)
100
95
101
- if not ignore_errors and error_found :
102
- if isinstance (error , bytes ):
103
- message = b"Utility exited with non-zero code. Error: " + error
104
- else :
105
- message = f"Utility exited with non-zero code. Error: { error } "
96
+ assert type (error_found ) == bool # noqa: E721
97
+
98
+ if encoding :
99
+ result = result .decode (encoding )
100
+ error = error .decode (encoding )
101
+
102
+ if not ignore_errors and error_found and not expect_error :
103
+ error = normalize_error (error )
104
+ assert type (error ) == str # noqa: E721
105
+ message = "Utility exited with non-zero code. Error: " + error
106
106
raise ExecUtilException (message = message , command = cmd , exit_code = exit_status , out = result )
107
107
108
108
if verbose :
0 commit comments