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

Ignore syntax errors #9

Open
isidentical opened this issue Jan 15, 2022 · 1 comment
Open

Ignore syntax errors #9

isidentical opened this issue Jan 15, 2022 · 1 comment
Labels
good first issue Good for newcomers

Comments

@isidentical
Copy link
Owner

For files that contain syntax errors, instead of crashing immediately we should simply ignore it (just like other tools, e.g black).

@isidentical isidentical added the good first issue Good for newcomers label Jan 15, 2022
@nega0
Copy link

nega0 commented Aug 16, 2023

Not the most robust, but this enough to id misbehaving files, and to work around #20.

diff --git a/teyit.py b/teyit.py
index 60f87ad..d3f84f4 100644
--- a/teyit.py
+++ b/teyit.py
@@ -334,7 +334,11 @@ def _refactor_file(path, **kwargs):
     with tokenize.open(path) as file:
         source = file.read()
         encoding = file.encoding
-    refactored_source, refactors = refactor_until_deterministic(source, **kwargs)
+    try:
+        refactored_source, refactors = refactor_until_deterministic(source, **kwargs)
+    except SyntaxError:
+        print(f"Failed: {path}")
+        return []
     if refactored_source != source:
         path.write_text(refactored_source, encoding=encoding)
     return refactors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants