-
Notifications
You must be signed in to change notification settings - Fork 0
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
styra-link: unhandled bad download URL for styra CLI causes cryptic error #78
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Author notes below:
if (!await StyraInstall.styraCmdExists()) { | ||
info(`"${STYRA_CLI_CMD}" not found; aborting ${command.title}`); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR bonus: OK, let's abort then!
if (!StyraInstall.checkWorkspace()) { | ||
teeError('Something is wrong! Did you forget to run checkWorkspace in your command?'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR bonus: Not clear why this would ever have been useful, as the only way this appears is if we are running checkWorkspace in the prior line. 😱
StyraInstall.styraCmdExists = jest.fn().mockResolvedValue(true); | ||
IDE.getConfigValue = mockVSCodeSettings(); | ||
|
||
beforeEach(() => { | ||
StyraInstall.styraCmdExists = jest.fn().mockResolvedValue(true); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR bonus: turns out that the PR bonus above that really did abort when it claimed to exposed an error in the test; this line needed to be in the beforeEach block for the tests to pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR boni seem OK, I'm wondering about the check though -- I'd think acting on the HTTP status would be cleaner. Can we do that, or is that path blocked for some reason?
eec1d5e
to
f88eedc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
794c661
to
a19caf5
Compare
With a bad URL the download still resulted in something, (seemed to be a web page indicating 404) so the code blithely installed that as /usr/local/bin/styra. With that in place, trying to invoke it as an executable resulted in the cryptic error "Error spawn Unknown system error -8". This change now recognizes that the non-empty download was not an executable, so fails the "install" operation properly.
not clear why this was ever useful
Getting here would be very rare, though, if even possible at all, because the checkStartup before would ensure CLI installation.
f88eedc
to
f817a83
Compare
What code changed, and why?
With a bad URL the automatic install of the Styra CLI by the Styra VSCode plugin still resulted in storing something at /usr/local/bin/styra, but not an executable binary(!). (Looks like a 404 page, essentially.) The code assumed that was the real thing, reported the CLI installation successful(!), tried to invoke it as the styra CLI, and said "Error spawn Unknown system error -8", as shown:
This PR will now let the plugin recognize that the non-empty download was not an executable, so fails the "install" operation properly.
The solution here is not terribly elegant—just seeing if the download was larger than one megabyte—but it is a fast check.
I opted for fast rather than thorough because something like this would happen only rarely (like, um, well, now). 🤷
Again, because it is rare, this handles the case of /usr/local/bin/styra being an imposter at install time only. The other case—which it does not handle—is if you already have an imposter /usr/local/bin/styra when you try to run
Styra Link: Initialize...
Definition of done
With the current bad URLs for downloading the styra CLI, the system will now recognize the attempted install of /usr/local/bin/styra failed and abort at that point.
2024.04.16 update:
Using the HTTP response instead of my initial crude approach; also adjusted the output here slightly:
How to test
You can install either from source code or from GitHub.
Install from source
npm install
.Install from GitHub
vscode-styra-2.0.1-next.2.vsix
.code --install-extension vscode-styra-2.0.1-next.2.vsix
Exercise the Code
Make sure you do not have
styra
on your search path, and in particular that you do not have it in /usr/local/bin, since that is where the plugin installs to.Attempt to run the VSCode palette command
Styra Link: Initialize...
.Say "Yes" when asked if you want to install the Styra CLI.
Observe the Output pane.