Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only surface errors when stderr is present #343

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions ruff_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ async def _lint_document_impl(document: Document) -> list[Diagnostic]:
# diagnostics, 1 indicates successful completion with remaining diagnostics,
# and 2 indicates an error.
if result.exit_code not in (0, 1):
show_error(f"Ruff: Lint failed ({result.stderr.decode('utf-8')})")
if result.stderr:
show_error(f"Ruff: Lint failed ({result.stderr.decode('utf-8')})")
return []

return _parse_output(result.stdout) if result.stdout else []
Expand Down Expand Up @@ -1110,7 +1111,8 @@ async def apply_format(arguments: tuple[TextDocument]):

# For `ruff format`, 0 indicates successful completion, non-zero indicates an error.
if result.exit_code != 0:
show_error(f"Ruff: Format failed ({result.stderr.decode('utf-8')})")
if result.stderr:
show_error(f"Ruff: Format failed ({result.stderr.decode('utf-8')})")
return None

workspace_edit = _result_to_workspace_edit(document, result)
Expand All @@ -1132,7 +1134,8 @@ async def format_document(params: DocumentFormattingParams) -> list[TextEdit] |

# For `ruff format`, 0 indicates successful completion, non-zero indicates an error.
if result.exit_code != 0:
show_error(f"Ruff: Format failed ({result.stderr.decode('utf-8')})")
if result.stderr:
show_error(f"Ruff: Format failed ({result.stderr.decode('utf-8')})")
return None

if not VERSION_REQUIREMENT_EMPTY_OUTPUT.contains(
Expand Down Expand Up @@ -1167,7 +1170,8 @@ async def _fix_document_impl(
# diagnostics, 1 indicates successful completion with remaining diagnostics,
# and 2 indicates an error.
if result.exit_code not in (0, 1):
show_error(f"Ruff: Fix failed ({result.stderr.decode('utf-8')})")
if result.stderr:
show_error(f"Ruff: Fix failed ({result.stderr.decode('utf-8')})")
return None

return _result_to_workspace_edit(document, result)
Expand Down
Loading