From 45eebeaea76fe016214e7cd4d61c85525605959a Mon Sep 17 00:00:00 2001 From: Stephen Macke Date: Wed, 6 Sep 2023 17:09:25 -0700 Subject: [PATCH] fix null reference for syntax errors due to invalid encodings in pyflakes plugin --- pylsp/plugins/pyflakes_lint.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pylsp/plugins/pyflakes_lint.py b/pylsp/plugins/pyflakes_lint.py index 404f045c..28a37b3f 100644 --- a/pylsp/plugins/pyflakes_lint.py +++ b/pylsp/plugins/pyflakes_lint.py @@ -52,6 +52,9 @@ def syntaxError(self, _filename, msg, lineno, offset, text): # We've seen that lineno and offset can sometimes be None lineno = lineno or 1 offset = offset or 0 + # could be None if the error is due to an invalid encoding + # see e.g. https://github.com/python-lsp/python-lsp-server/issues/429 + text = text or "" err_range = { "start": {"line": lineno - 1, "character": offset},