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

Language server crashes with partially-quoted heredoc #266

Open
sethp opened this issue Sep 25, 2023 · 3 comments
Open

Language server crashes with partially-quoted heredoc #266

sethp opened this issue Sep 25, 2023 · 3 comments

Comments

@sethp
Copy link

sethp commented Sep 25, 2023

Here's the story so far: I'm futzing around with the heredoc support with Dockerfile syntax >=1.3, and it turns out to be excellent at applying small inline patches like so:

RUN <<END_OF_PATCH tee /dev/stderr | git apply
diff --git a/file b/file
....
END_OF_PATCH

That tee is in there because I was getting a strange "patch does not apply", and that's how I learned that the heredoc support is implemented entirely in the parsing front-end and gets turned into a carefully ARGV'd shell command:

ERROR: failed to solve: process "/bin/sh -c <<END_OF_PATCH tee /dev/stderr | git apply\ndiff --git

(NB: this isn't easily copy-pasteable because the shell that invokes /bin/sh will do word splitting and turn that into a mess, but that's another story)

What this means is that, since a heredoc acts much like a double-quoted shell string, metacharacters (i.e. $) were getting interpreted, changing the contents of my patch from something like - echo ${HELLO} to - echo <whatever value of HELLO was in the shell's environment, usually nothing>. Oops. Well, good thing there's a provision in the shell for a situation like this, I think, and I type this into my editor (on my way to turning the heredoc word into 'END_OF_PATCH'):

RUN <<'END_OF_PATCH tee /dev/stderr | git apply

and, to my surprise, the language server immediately crashes with this output:

TypeError: Cannot read properties of undefined (reading 'getRange')
    at Run.getHeredocs (/home/seth/.vscode-oss/extensions/ms-azuretools.vscode-docker-1.26.1/dist/dockerfile-language-server-nodejs/lib/server.js:1:20724)
    at Run.getHeredocs (/home/seth/.vscode-oss/extensions/ms-azuretools.vscode-docker-1.26.1/dist/dockerfile-language-server-nodejs/lib/server.js:1:28798)
    at Validator.getHeredocLines (/home/seth/.vscode-oss/extensions/ms-azuretools.vscode-docker-1.26.1/dist/dockerfile-language-server-nodejs/lib/server.js:1:63517)
    at Validator.validateInstruction (/home/seth/.vscode-oss/extensions/ms-azuretools.vscode-docker-1.26.1/dist/dockerfile-language-server-nodejs/lib/server.js:1:64127)
    at Validator.validate (/home/seth/.vscode-oss/extensions/ms-azuretools.vscode-docker-1.26.1/dist/dockerfile-language-server-nodejs/lib/server.js:1:63270)
    at Object.validate (/home/seth/.vscode-oss/extensions/ms-azuretools.vscode-docker-1.26.1/dist/dockerfile-language-server-nodejs/lib/server.js:1:102617)
    at LanguageService.validate (/home/seth/.vscode-oss/extensions/ms-azuretools.vscode-docker-1.26.1/dist/dockerfile-language-server-nodejs/lib/server.js:1:219425)
    at /home/seth/.vscode-oss/extensions/ms-azuretools.vscode-docker-1.26.1/dist/dockerfile-language-server-nodejs/lib/server.js:1:427396

In playing around with the demo site (very cool!), I got a similar-looking crash out of this minimal example:

RUN <<'END_OF_PATCH
END_OF_PATCH

That's definitely invalid syntax, so I'm not sure what the right response for the language server would be, but crashing on the input means that VS Code gives up after the 5th try (~instantaneously, since the startup is so fast).

@rcjsuen
Copy link
Owner

rcjsuen commented Oct 6, 2023

@sethp Thanks for your bug report. I am unable to reproduce this at the moment.

In playing around with the demo site (very cool!)

RUN <<'END_OF_PATCH
END_OF_PATCH

I also tried it on the demo site (which is actually a few versions behind due to compatibility issues) and I could not reproduce it there either.

image

Do you see it crash if you just open VS Code right from the beginning?

@sethp
Copy link
Author

sethp commented Oct 6, 2023

Hmm, you're right: that minimal example was too minimal, sorry. When I tried it again, I got the same crash in the demo site from the full Dockerfile (which I'm happy to provide, it's just A Lot), and narrowed it down to just this example that seems to crash every time I paste it into a freshly-loaded tab:

RUN <<'END_OF_PATCH
END_OF_PATCH
RUN <<'SCRIPT'
SCRIPT

image

@rcjsuen
Copy link
Owner

rcjsuen commented Oct 6, 2023

@sethp Thank you very much for your new example! I am able to reproduce the bug and have opened rcjsuen/dockerfile-ast#114 to track this. I will leave this issue opened until the fix has been merged into the language server itself.

Have a great weekend!

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