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

IOError encountered opening file hidden by AttributeError #200

Closed
asottile opened this issue Apr 3, 2021 · 13 comments
Closed

IOError encountered opening file hidden by AttributeError #200

asottile opened this issue Apr 3, 2021 · 13 comments

Comments

@asottile
Copy link
Member

asottile commented Apr 3, 2021

In GitLab by @dopplershift on Nov 21, 2016, 15:25

Currently if you hit a permission problem on a file (or at least that's my best guess of what went wrong on AppVeyor), you get:

Traceback (most recent call last):
  File "C:\Miniconda\envs\_test\Scripts\flake8-script.py", line 11, in <module>
    load_entry_point('flake8==3.2.1', 'console_scripts', 'flake8')()
  File "C:\Miniconda\envs\_test\lib\site-packages\flake8\main\cli.py", line 16, in main
    app.run(argv)
  File "C:\Miniconda\envs\_test\lib\site-packages\flake8\main\application.py", line 322, in run
    self._run(argv)
  File "C:\Miniconda\envs\_test\lib\site-packages\flake8\main\application.py", line 306, in _run
    self.run_checks()
  File "C:\Miniconda\envs\_test\lib\site-packages\flake8\main\application.py", line 243, in run_checks
    self.file_checker_manager.start(files)
  File "C:\Miniconda\envs\_test\lib\site-packages\flake8\checker.py", line 371, in start
    self.make_checkers(paths)
  File "C:\Miniconda\envs\_test\lib\site-packages\flake8\checker.py", line 285, in make_checkers
    if argument == filename or should_create_file_checker(filename)
  File "C:\Miniconda\envs\_test\lib\site-packages\flake8\checker.py", line 412, in __init__
    self.display_name = self.processor.filename
AttributeError: 'NoneType' object has no attribute 'filename'

This is due to the combination of setting FileChecker.display_name to self.processor.filename at https://gitlab.com/pycqa/flake8/blob/master/src/flake8/checker.py#L412 and the fact that FileChecker._make_processor() returns None in the error path at https://gitlab.com/pycqa/flake8/blob/master/src/flake8/checker.py#L412.

Not the cause of my problem, but it keeps me from ever seeing the error message from IOError.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @dopplershift on Nov 21, 2016, 15:25

Changed title: Poor message ifPoor message if{+ IOError encountered opening file+}

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @dopplershift on Nov 21, 2016, 15:28

Changed title: {-Poor message if IOError encountered opening file-}{+IOError encountered opening file hidden by AttributeError+}

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 23, 2016, 14:49

Mentioned in merge request !157

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 23, 2016, 14:50

Status changed to closed by commit b8ce133

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @dopplershift on Nov 23, 2016, 15:21

Here's a patch I put together so that I could get flake8 to finally print out the message:

diff -rupN flake8-3.2.1/src/flake8/checker.py flake8-3.2.1-patched/src/flake8/checker.py
--- flake8-3.2.1/src/flake8/checker.py	2016-11-19 18:30:53.000000000 -0700
+++ flake8-3.2.1-patched/src/flake8/checker.py	2016-11-22 15:39:36.000000000 -0700
@@ -409,11 +409,16 @@ class FileChecker(object):
         self.checks = checks
         self.results = []
         self.processor = self._make_processor()
-        self.display_name = self.processor.filename
+        if self.processor:
+            self.display_name = self.processor.filename
+            lines = len(self.processor.lines)
+        else:
+            self.display_name = self.filename
+            lines = 0
         self.statistics = {
             'tokens': 0,
             'logical lines': 0,
-            'physical lines': len(self.processor.lines),
+            'physical lines': lines,
         }
 
     def _make_processor(self):
@@ -594,6 +599,11 @@ class FileChecker(object):
 
     def run_checks(self, results_queue, statistics_queue):
         """Run checks against the file."""
+        if not self.processor:
+            if results_queue is not None:
+                results_queue.put((self.filename, self.results))
+            return
+
         if self.processor.should_ignore_file():
             return

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @dopplershift on Nov 23, 2016, 15:22

I'm not sure I see how !157 relates to this issue....

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 28, 2016, 12:59

Mentioned in commit asottile/flake8@b8ce133

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @asottile on Nov 29, 2016, 08:11

I am in fact hitting this and fixing it as part of https://gitlab.com/pycqa/flake8/merge_requests/156

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @alexwlchan on Nov 30, 2016, 13:04

An IOError seems like a plausible guess – I can reproduce this issue by asking flake8 to check a non-existent file:

$ flake8 thisfiledoesnotexist.py
Traceback (most recent call last):
  File "/Users/alexwlchan/.virtualenvs/specktre/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/Users/alexwlchan/.virtualenvs/specktre/lib/python3.5/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/Users/alexwlchan/.virtualenvs/specktre/lib/python3.5/site-packages/flake8/main/application.py", line 322, in run
    self._run(argv)
  File "/Users/alexwlchan/.virtualenvs/specktre/lib/python3.5/site-packages/flake8/main/application.py", line 306, in _run
    self.run_checks()
  File "/Users/alexwlchan/.virtualenvs/specktre/lib/python3.5/site-packages/flake8/main/application.py", line 243, in run_checks
    self.file_checker_manager.start(files)
  File "/Users/alexwlchan/.virtualenvs/specktre/lib/python3.5/site-packages/flake8/checker.py", line 371, in start
    self.make_checkers(paths)
  File "/Users/alexwlchan/.virtualenvs/specktre/lib/python3.5/site-packages/flake8/checker.py", line 275, in make_checkers
    for argument in paths
  File "/Users/alexwlchan/.virtualenvs/specktre/lib/python3.5/site-packages/flake8/checker.py", line 285, in <listcomp>
    if argument == filename or should_create_file_checker(filename)
  File "/Users/alexwlchan/.virtualenvs/specktre/lib/python3.5/site-packages/flake8/checker.py", line 412, in __init__
    self.display_name = self.processor.filename
AttributeError: 'NoneType' object has no attribute 'filename'

flake8 3.2.1, Python 3.5.2.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Dec 4, 2016, 09:41

mentioned in commit sigmavirus24/flake8@e4582ef

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @fermulator on Jan 10, 2017, 17:38

I can confirm that patch noted in https://gitlab.com/pycqa/flake8/issues/268#note_18889944 solves the issue.

The input which caused the problem was doing something like this:
flake8 '' <real_file_path>

I had a script which was accidentally passing in two single quotes (due to empty string) as the first parameter (which was intended to be a list of args)

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Jan 27, 2017, 13:29

This is fixed and will be released in 3.3.0

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Jan 27, 2017, 13:29

closed

@asottile asottile closed this as completed Apr 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant