Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 99c2dfd

Browse files
committed
Print parse errors to command line.
1 parent 774c10d commit 99c2dfd

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

src/pydocstyle/checker.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from . import violations
1212
from .config import IllegalConfiguration
1313
from .parser import (Package, Module, Class, NestedClass, Definition, AllError,
14-
Method, Function, NestedFunction, Parser, StringIO)
14+
Method, Function, NestedFunction, Parser, StringIO,
15+
ParseError)
1516
from .utils import log, is_blank, pairwise
1617
from .wordlists import IMPERATIVE_VERBS, IMPERATIVE_BLACKLIST, stem
1718

@@ -695,8 +696,9 @@ def check(filenames, select=None, ignore=None, ignore_decorators=None):
695696
code = getattr(error, 'code', None)
696697
if code in checked_codes:
697698
yield error
698-
except (EnvironmentError, AllError):
699-
yield sys.exc_info()[1]
699+
except (EnvironmentError, AllError, ParseError) as error:
700+
log.warning('Error in file %s: %s', filename, error)
701+
yield error
700702
except tk.TokenError:
701703
yield SyntaxError('invalid syntax in file %s' % filename)
702704

src/pydocstyle/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def run_pydocstyle():
4949

5050
count = 0
5151
for error in errors:
52-
sys.stdout.write('%s\n' % error)
52+
if hasattr(error, 'code'):
53+
sys.stdout.write('%s\n' % error)
5354
count += 1
5455
if count == 0:
5556
exit_code = ReturnCode.no_violations_found

src/pydocstyle/parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def next(obj, default=nothing):
3333

3434

3535
class ParseError(Exception):
36-
pass
36+
def __str__(self):
37+
return "cannot parse file"
3738

3839

3940
def humanize(string):

src/tests/test_integration.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,3 +964,15 @@ def foo():
964964
_, _, code = env.invoke()
965965

966966
assert code == 0
967+
968+
969+
def test_syntax_error_multiple_files(env):
970+
"""Test that a syntax error in a file doesn't prevent further checking."""
971+
for filename in ('first.py', 'second.py'):
972+
with env.open(filename, 'wt') as fobj:
973+
fobj.write("[")
974+
975+
out, err, code = env.invoke(args="-v")
976+
assert code == 1
977+
assert 'first.py: cannot parse file' in err
978+
assert 'second.py: cannot parse file' in err

0 commit comments

Comments
 (0)