异常处理 :param params: :param spc: :return:
(self, params, spc, file_path)
| 252 | return issues |
| 253 | |
| 254 | def error_handle(self, params, spc, file_path): |
| 255 | """ |
| 256 | 异常处理 |
| 257 | :param params: |
| 258 | :param spc: |
| 259 | :return: |
| 260 | """ |
| 261 | source_dir = params["source_dir"] |
| 262 | if spc.returncode == 0: |
| 263 | return |
| 264 | spc_err = spc.get_stderr() |
| 265 | if not spc_err: |
| 266 | log = "" |
| 267 | else: |
| 268 | log = spc_err.read() |
| 269 | spc_err.close() |
| 270 | if ( |
| 271 | log.find( |
| 272 | "com.puppycrawl.tools.checkstyle.api.CheckstyleException: " "Exception was thrown while processing" |
| 273 | ) |
| 274 | != -1 |
| 275 | ): |
| 276 | msg = "CheckStyle工具解析异常,请确保Java文件语法正确" |
| 277 | line_num = 1 |
| 278 | for line in log.split("\n"): |
| 279 | if line.find("Caused by: line ") != -1: |
| 280 | line_num = self.format_parse_error(line) |
| 281 | msg += line |
| 282 | return { |
| 283 | "rule": "JavaParseError", |
| 284 | "path": os.path.relpath(file_path, source_dir), |
| 285 | "line": line_num, |
| 286 | "column": 1, |
| 287 | "msg": msg, |
| 288 | } |
| 289 | elif ( |
| 290 | log.find( |
| 291 | "com.puppycrawl.tools.checkstyle.api.CheckstyleException: " |
| 292 | "NoViableAltException occurred during the analysis of file" |
| 293 | ) |
| 294 | != -1 |
| 295 | ): |
| 296 | raise AnalyzeTaskError("CheckStyle工具解析异常,请排查log确保对应文件语法是否正确。") |
| 297 | |
| 298 | elif ( |
| 299 | log.find("com.puppycrawl.tools.checkstyle.api.CheckstyleException: " "cannot initialize module TreeWalker") |
| 300 | != -1 |
| 301 | ): |
| 302 | raise AnalyzeTaskError("CheckStyle工具执行异常,配置文件有误,可能是规则名称不匹配。") |
| 303 | elif log.find("com.puppycrawl.tools.checkstyle.api.CheckstyleException:") != -1: |
| 304 | raise AnalyzeTaskError("CheckStyle工具执行异常。") |
| 305 | return None |
| 306 | |
| 307 | def get_issue(self, line): |
| 308 | """ |
no test coverage detected