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

Unable to run format due to missing flag #65

Open
pauheri opened this issue Oct 7, 2022 · 7 comments
Open

Unable to run format due to missing flag #65

pauheri opened this issue Oct 7, 2022 · 7 comments
Assignees

Comments

@pauheri
Copy link

pauheri commented Oct 7, 2022

When trying to format some documents the extension provides two error boxes:

  1. SQLFluff templating/parsing errors found
  2. Fix aborted due to unparseable template variables. Use --FIX-EVEN-UNPARSABLE' to attempt to fix the SQL anyway

I am currently using it with the dialect redshift and Linter:Run onType, I think that's all the changes I have in the config.

Is there a way to add the flag in the settings json? I haven't found any in the docs.

@RobertOstermann
Copy link
Contributor

You could try setting the sqlfluff.ignoreParsing setting to true. If that doesn't work, try setting the sqlfluff.executablePath to include that flag. For example, sqlfluff.executablePath = "sqlfluff --FIX-EVEN-UNPARSABLE".

Let me know if either of those options works for you, if not I can add a setting to allow you to pass in arguments manually.

@RobertOstermann RobertOstermann self-assigned this Oct 7, 2022
@pauheri
Copy link
Author

pauheri commented Oct 10, 2022

I've just tried both, restarting vscode after each change just to be on the safe side.
The sqlfluff.ignoreParsing lead to the same result, changing the executable path to add the flag resulted in the following error The sqlfluff executable was not found. Use the 'Executable Path' setting to configure the location of the executable, or add it to your PATH.. I've tried running the path without the flag and it seems to be ok.

@RobertOstermann
Copy link
Contributor

Try v0.1.4 and use the format.arguments option to add the argument.

@pauheri
Copy link
Author

pauheri commented Oct 13, 2022

I've updated to v0.1.4 and set the option in the settings.json as "sqlfluff.format.arguments": ["--FIX-EVEN-UNPARSABLE"], . However I am still getting the same error box (Fix aborted due to unparseable template variables. Use --FIX-EVEN-UNPARSABLE' to attempt to fix the SQL anyway). Maybe I have something else not properly set?
My other sqlfluff related config is:

    "sqlfluff.rules": [
    
    ],
    "sqlfluff.executablePath": "/Users/pau/miniconda3/bin/sqlfluff",
    "sqlfluff.excludeRules": [
      
    ],
    "files.associations": {
        "*.sql": "jinja-sql"
    },
    "sqlfluff.dialect": "redshift",
    "sqlfluff.ignoreParsing" : true,
    "sqlfluff.format.arguments": ["--FIX-EVEN-UNPARSABLE"],
    ```

@RobertOstermann
Copy link
Contributor

Can you check the output tab and look at the SQLFluff channel. This will tell you the exact command it is executing when the formatting is taking place. Copy that command and try running it in the terminal and see if the output is the same. If the "--FIX-EVEN-UNPARSABLE flag is not there add it and see if that works on the terminal.

@pauheri
Copy link
Author

pauheri commented Oct 13, 2022

The output tab does have the flag, it does not have the path to the file it's trying to format (although the file content is in the output tab) and the command finishes with a - :


--------------------Executing Command--------------------

/Users/pau/miniconda3/bin/sqlfluff fix --force --FIX-EVEN-UNPARSABLE --dialect redshift --ignore parsing -

------------------------------------------------------------

However I tried running /Users/pau/miniconda3/bin/sqlfluff fix path_to_file.sql --force --FIX-EVEN-UNPARSABLE --dialect redshift --ignore parsing and it did work, formatting the file (with some unfixable stuff showing a WARNING One fix for L005 not applied, it would re-cause the same error. in the terminal output)

@RobertOstermann
Copy link
Contributor

The command finished with - because I am letting sqlfluff know that it needs to format using stdin content, which I pass in after executing that command. I wonder if it won't work because of the warnings? I'm not sure. I can try to look into this more when I have some time, but that might be a while.

For now, could you try setting "sqlfluff.experimental.format.executeInTerminal": true,. That forces the extension to pass in the file path instead of using stdin, but can come with some drawbacks as editing the file while the formatting is taking place causes an issue, but that is not too big of a deal. I'm hopeful that this would at least do the formatting though.

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

2 participants