Skip to content

Error on save in buffer_post_write - missing endif #452

Closed

Description

@bgr

I've isolated a piece of python code that will cause an error after doing :w on a62f8ab:

foo() = 1

The error:

[Pymode] Code checking is running ...
Error detected while processing function pymode#buffer_post_write..pymode#lint#check:
line   11:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/.../.vim/bundle/python-mode/pymode/lint.py", line 71, in code_check
    env.run('g:PymodeLocList.current().extend', [e._info for e in errors])
  File "/home/.../.vim/bundle/python-mode/pymode/environment.py", line 186, in run
    self.prepare_value(a) for a in args
vim.error: Vim(call):E121: Undefined variable: null
Error detected while processing function pymode#buffer_post_write:
line   10:
E171: Missing :endif

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Activity

  1. krader1961 commented on Jul 11, 2014

    @krader1961
    Contributor

    I can't reproduce that error. However, putting foo() = 1 in one of my modules does cause this failure which makes more sense:

    Run pyflakes {'builtins': '_'}
    <traceback object at 0x101bd5fc8>
    SyntaxError can't assign to function call (main.py, line 442)
    

    What is slightly perplexing is that other types of syntax errors I introduced in my test module are detected and reported without causing an uncaught exception. Based on several other recently reported bugs that resulted in the linters throwing exceptions it might be a good idea to wrap the check_path() call in lint.py in a try block to catch and report unexpected exceptions.

  2. aseyboldt commented on Jul 25, 2014

    @aseyboldt

    I get the same error message on python code like this with version g2df674c

    foo(self._a=5)
    
  3. kirkboyer-wf commented on Aug 25, 2014

    @kirkboyer-wf

    I got nearly exact same Traceback as bgr:

    E121: Undefined variable: null
    E116: Invalid arguments for function 12
    Traceback (most recent call last):
    File "", line 1, in
    File "/Users/.../.vim/bundle/python-mode/pymode/lint.py", line 71, in code_check
    env.run('g:PymodeLocList.current().extend', [e._info for e in errors])
    File "/Users/.../.vim/bundle/python-mode/pymode/environment.py", line 186, in run
    self.prepare_value(a) for a in args
    vim.error

    This happens when I make a particular kind of error in using google's app engine entity queries:
    If I have a model called MyModel with a property called value, in models.py, then writing a file containing the following causes this error:

    import models
    something = models.MyModel.query(models.MyModel.value=3)

    (This code, correctly written, would have the line
    something = models.MyModel.query(models.MyModel.value == 3)
    )

  4. bsandrow commented on Oct 24, 2014

    @bsandrow

    I will toss my +1 in with @kirkboyer-wf . I'm using SQLAlchemy, and I wrote a query as:

    import models
    
    result = models.MyModel.query.filter(models.MyModel.id = 1)

    Rather than:

    import models
    
    result = models.MyModel.query.filter(models.MyModel.id == 1)

    It caused this issue. I pulled the latest version of the develop branch (I use Vundle), but the issue is still present.

  5. bsandrow commented on Oct 24, 2014

    @bsandrow

    More info:

    It's blowing up on this line:

    env.run('g:PymodeLocList.current().extend', [e._info for e in errors])

    env.run() does some preparation on the e._infos that are passed through. The e._info that's blowing up in this case looks like:

    ERROR[0]._info = {'bufnr': 1,
     'col': None,
     'filename': 'sowingo/api/resources/office_inventory.py',
     'linter': 'pyflakes',
     'lnum': 290,
     'number': 'keyword',
     'rel': 'sowingo/api/resources/office_inventory.py',
     'text': "keyword can't be an expression [pyflakes]",
     'type': 'E'}

    The output of pyflakes looks like:

    sowingo/api/resources/office_inventory.py:290: keyword can't be an expression
    office_inventory_lists_to_items.office_inventory_list_id = list_id
    

    So the None column is there because PyFlakes gives no column. So...

    env.run() calls env.prepare_args() on each of the arguments (in this case each e._info instance). This basically just runs json.dumps() on the value, and does some unicode cleanup if we're in on Python 2.x (but this part isn't blowing up). The actual error is vim.error: Vim(call):E121: Undefined variable: null. Since we're basically turning the arguments of env.run() into a :call command:

        def run(self, name, *args):
            """ Run vim function. """
            vim.command('call %s(%s)' % (name, ", ".join([
                self.prepare_value(a) for a in args
            ])))

    I don't think that it likes the null column (since that's the only value that could end up as null that's being passed through).

    Patching it from:

        for e in errors:
            e._info['bufnr'] = env.curbuf.number

    to:

        for e in errors:
            e._info['bufnr'] = env.curbuf.number
            if e._info['col'] is None:
                e._info['col'] = 1

    seems to do the trick (at least for now).

  6. bsandrow commented on Oct 24, 2014

    @bsandrow

    There is probably a better way to deal with this (as the error report now says that the column is "1" which isn't true), but for those that want a quick patch this should work. Here's the patch:

    diff --git a/pymode/lint.py b/pymode/lint.py
    index 5053f7f..57fda6f 100644
    --- a/pymode/lint.py
    +++ b/pymode/lint.py
    @@ -67,6 +67,16 @@ def code_check():
    
         for e in errors:
             e._info['bufnr'] = env.curbuf.number
    +        if e._info['col'] is None:
    +            e._info['col'] = 1
    +
    +    with open('/tmp/dump.txt', 'wb') as fh:
    +        import pprint
    +        for i, e in enumerate(errors):
    +            fh.write('ERROR[%d]._info = %s' % (
    +                i,
    +                pprint.pformat(e._info)
    +            ))
    
         env.run('g:PymodeLocList.current().extend', [e._info for e in errors])

    You can remove the error dump if you like, but it was useful for debugging.

  7. stale commented on Feb 13, 2018

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  8. stale commented on Mar 6, 2018

    @stale

    Closed due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions