|
8 | 8 | from . import __version__ |
9 | 9 | from . import get_build_date |
10 | 10 | from . import get_version |
| 11 | +from . import Error |
11 | 12 | from . import LanguageTool |
12 | 13 |
|
13 | 14 |
|
@@ -116,33 +117,37 @@ def main(): |
116 | 117 | lang_tool.disabled.update(args.disable) |
117 | 118 | lang_tool.enabled.update(args.enable) |
118 | 119 |
|
119 | | - if args.api: |
120 | | - print(lang_tool._check_api(text).decode()) |
121 | | - elif args.apply: |
122 | | - print(lang_tool.correct(text)) |
123 | | - else: |
124 | | - for match in lang_tool.check(text): |
125 | | - rule_id = match.ruleId |
126 | | - if match.subId is not None: |
127 | | - rule_id += '[{}]'.format(match.subId) |
128 | | - |
129 | | - replacement_text = ', '.join( |
130 | | - "'{}'".format(word) |
131 | | - for word in match.replacements).strip() |
132 | | - |
133 | | - message = match.msg |
134 | | - |
135 | | - # Messages that end with punctuation already include the |
136 | | - # suggestion. |
137 | | - if replacement_text and not message.endswith(('.', '?')): |
138 | | - message += '; suggestions: ' + replacement_text |
139 | | - |
140 | | - print('{}:{}:{}: {}: {}'.format( |
141 | | - filename, |
142 | | - match.fromy + 1, |
143 | | - match.fromx + 1, |
144 | | - rule_id, |
145 | | - message)) |
146 | | - status = 2 |
| 120 | + try: |
| 121 | + if args.api: |
| 122 | + print(lang_tool._check_api(text).decode()) |
| 123 | + elif args.apply: |
| 124 | + print(lang_tool.correct(text)) |
| 125 | + else: |
| 126 | + for match in lang_tool.check(text): |
| 127 | + rule_id = match.ruleId |
| 128 | + if match.subId is not None: |
| 129 | + rule_id += '[{}]'.format(match.subId) |
| 130 | + |
| 131 | + replacement_text = ', '.join( |
| 132 | + "'{}'".format(word) |
| 133 | + for word in match.replacements).strip() |
| 134 | + |
| 135 | + message = match.msg |
| 136 | + |
| 137 | + # Messages that end with punctuation already include the |
| 138 | + # suggestion. |
| 139 | + if replacement_text and not message.endswith(('.', '?')): |
| 140 | + message += '; suggestions: ' + replacement_text |
| 141 | + |
| 142 | + print('{}:{}:{}: {}: {}'.format( |
| 143 | + filename, |
| 144 | + match.fromy + 1, |
| 145 | + match.fromx + 1, |
| 146 | + rule_id, |
| 147 | + message)) |
| 148 | + status = 2 |
| 149 | + except Error as exception: |
| 150 | + print('{}: {}'.format(filename, exception), file=sys.stderr) |
| 151 | + continue |
147 | 152 |
|
148 | 153 | return status |
0 commit comments