30
30
import six
31
31
32
32
33
+ class CheckerCommandException (Exception ):
34
+ """Raised when running a checker failed.
35
+
36
+ Attributes:
37
+ checker: Checker command name.
38
+ path: Path to the file being validated.
39
+ errno: Error number from the checker execution error.
40
+ msg: Message from the checker execution error.
41
+
42
+ """
43
+
44
+ def __init__ (self , cmd , oserror ):
45
+ self .checker = cmd [0 ]
46
+ self .path = cmd [- 1 ]
47
+ self .errno = oserror .errno
48
+ self .msg = str (oserror )
49
+
50
+
33
51
class BadFiles (BeetsPlugin ):
34
52
def run_command (self , cmd ):
35
53
self ._log .debug (u"running command: {}" ,
@@ -43,12 +61,7 @@ def run_command(self, cmd):
43
61
errors = 1
44
62
status = e .returncode
45
63
except OSError as e :
46
- if e .errno == errno .ENOENT :
47
- raise ui .UserError (u"command not found: {}" .format (cmd [0 ]))
48
- else :
49
- raise ui .UserError (
50
- u"error invoking {}: {}" .format (cmd [0 ], e )
51
- )
64
+ raise CheckerCommandException (cmd , e )
52
65
output = output .decode (sys .getfilesystemencoding ())
53
66
return status , errors , [line for line in output .split ("\n " ) if line ]
54
67
@@ -97,14 +110,26 @@ def check_bad(self, lib, opts, args):
97
110
ext = os .path .splitext (item .path )[1 ][1 :].decode ('utf8' , 'ignore' )
98
111
checker = self .get_checker (ext )
99
112
if not checker :
100
- self ._log .debug (u"no checker available for {}" , ext )
113
+ self ._log .error (u"no checker specified in the config for {}" ,
114
+ ext )
101
115
continue
102
116
path = item .path
103
117
if not isinstance (path , six .text_type ):
104
118
path = item .path .decode (sys .getfilesystemencoding ())
105
- status , errors , output = checker (path )
119
+ try :
120
+ status , errors , output = checker (path )
121
+ except CheckerCommandException as e :
122
+ if e .errno == errno .ENOENT :
123
+ self ._log .error (
124
+ u"command not found: {} when validating file: {}" ,
125
+ e .checker ,
126
+ e .path
127
+ )
128
+ else :
129
+ self ._log .error (u"error invoking {}: {}" , e .checker , e .msg )
130
+ continue
106
131
if status > 0 :
107
- ui .print_ (u"{}: checker exited withs status {}"
132
+ ui .print_ (u"{}: checker exited with status {}"
108
133
.format (ui .colorize ('text_error' , dpath ), status ))
109
134
for line in output :
110
135
ui .print_ (u" {}" .format (displayable_path (line )))
0 commit comments