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

Fix for ClojureScript Quick Start path bug #2326

Merged

Conversation

AlbertSnows
Copy link
Contributor

@AlbertSnows AlbertSnows commented Oct 11, 2023

What has changed?

  • I have removed a catch that was silently hiding an exception that can cause calva to not display an error to the user
  • I have added a fix to the code where an exception is thrown via a problematic file path join. Instead of doing path.join on an array spread, we remove that join and do joinPath on the array that we were trying to join on.

More explanation is provided below the checklist.

Fixes #2325

My Calva PR Checklist

I have:

  • Read How to Contribute.
  • Directed this pull request at the dev branch. (Or have specific reasons to target some other branch.)
  • Made sure I have changed the PR base branch, so that it is not published. (Sorry for the nagging.)
  • Made sure there is an issue registered with a clear problem statement that this PR addresses, (created the issue if it was not present).
    • Updated the [Unreleased] entry in CHANGELOG.md, linking the issue(s) that the PR is addressing.
    • Referenced the issue I am fixing/addressing in a commit message for the pull request.
      • If I am fixing the issue, I have used GitHub's fixes/closes syntax
      • If I am fixing just part of the issue, I have just referenced it w/o any of the "fixes” keywords.
  • Figured if anything about the fix warrants tests on Mac/Linux/Windows/Remote/Whatever, and either tested it there if so, or mentioned it in the PR.
  • Added to or updated docs in this branch, if appropriate
  • Tests
    • Tested the particular change
    • Figured if the change might have some side effects and tested those as well.
  • Formatted all JavaScript and TypeScript code that was changed. (use the prettier extension or run npm run prettier-format)
  • Confirmed that there are no linter warnings or errors (use the eslint extension, run npm run eslint before creating your PR, or run npm run eslint-watch to eslint as you go).

Ping @PEZ, @bpringe, @corasaurus-hex, @Cyrik

Why is this happening?

This issue was uncovered in a huddle session less than an hour ago at time of writing. Explanations to follow.

Why isn't it showing an error to the user?

It's not showing an error to the user because the exception that is (presumably) thrown is being caught and silently logged to a console that (I think) isn't exposed to the user. Specifically, this line.

.catch((err) => {

Why isn't the command behaving as expected?

The command isn't working because of nuances with javascript's join behavior. Look at this line.

const dirUri = vscode.Uri.joinPath(storageUri, path.join(...path.dirname(filePath).split(/\//)));

When javascript joins these lines it results in code such as src\\hello_world instead of the desired src/hello_world. This is an invalid directory format, so the directory cannot be created! Thus when trying to act on these assumed created files, the function will throw an exception that is silently caught.

What is the solution?

The solution is twofold. First, remove the catch so that this error bubbles up and notifies the user. Second, remove the join since it's not needed to build the path connection for the file creation location; as follows.

  const directoryPath = path.dirname(filePath).split(/\//);
  const dirUri = vscode.Uri.joinPath(storageUri, ...directoryPath);

@netlify
Copy link

netlify bot commented Oct 11, 2023

Deploy Preview for calva-docs ready!

Name Link
🔨 Latest commit 390bffd
🔍 Latest deploy log https://app.netlify.com/sites/calva-docs/deploys/65272b3f2a551f0009d56544
😎 Deploy Preview https://deploy-preview-2326--calva-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@AlbertSnows AlbertSnows marked this pull request as ready for review October 12, 2023 00:06
@AlbertSnows
Copy link
Contributor Author

AlbertSnows commented Oct 12, 2023

@PEZ One thing I want to highlight is the outcome of side effects. I've tested on windows, but since I don't have the domain knowledge to assess the impact on either different windows platforms or other operating systems, I would suggest ensuring that this change doesn't break other assumptions from said platforms.
Fortunately, this function is only used in one spot. As such, I think the only question that comes to mind in terms of possible side effects of this change is the possible states of the parameters. There are three of them.

  • storageUri (of type vscode.Uri)
  • configPath (of type string)
  • filePath (of type string)

We know the types, but the remaining question in my mind is, "Are there any formats that these types come in that worked previously but may be broken with these new changes?" My assumption is no, but I will defer to you experience to make that judgement.

@AlbertSnows AlbertSnows changed the title Fix for javascript quickstart path bug (WIP) Fix for javascript quickstart path bug Oct 12, 2023
@PEZ PEZ changed the title Fix for javascript quickstart path bug Fix for ClojureScript Quick Start path bug Oct 12, 2023
@PEZ PEZ self-requested a review October 12, 2023 06:31
@@ -69,7 +69,8 @@ async function fetchConfig(configName: string): Promise<DramConfig> {

async function downloadDram(storageUri: vscode.Uri, configPath: string, filePath: string) {
const downloadUrl = `${dramsBaseUrl()}/${configPath}/${filePath}`;
const dirUri = vscode.Uri.joinPath(storageUri, path.join(...path.dirname(filePath).split(/\//)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have had a lot of problems with this category of mistakes. Most oft them we have found, but this one was still lurking in there! (I think we may still have some places undiscovered.)

@@ -84,13 +85,9 @@ export async function downloadDrams(
) {
await Promise.all(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: Consider returning the promise instead of awaiting it. Similar to how we shouldn't have catched the error here, I think it makes sense to push the promises out and up as close to the user as possible.

@PEZ
Copy link
Collaborator

PEZ commented Oct 12, 2023

Thanks for helping with improving Calva! 🙏 ❤️. Code looks great. I will try it on my Mac just to make sure I am understanding the issue correctly.

We could consider adding this to the end-to-end tests. What speaks against it is that the tests are already dependent on a lot of external things and this would add more of that.

@PEZ
Copy link
Collaborator

PEZ commented Oct 12, 2023

It still works on my Mac. (Or course it does!)

Good points about validation of the inputs there. At the moment we have full control of the whole chain, but my ambition is that more people will contribute drams (the configurations behind those Quick Start experiences) and then it will be very good to remember to help with that by validating inputs and generating good error messages.

@PEZ PEZ merged commit a8cb40a into BetterThanTomorrow:dev Oct 12, 2023
Comment on lines +7 to +9
## [2.0.391] - 2023-10-11

- Fix: [Allowing dram download to fail vocally for user. Fixing a JS join path error](https://github.com/BetterThanTomorrow/calva/issues/2325)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was reviewing a bit too fast. This entry should not have a date, nor a version. It should remain just Unreleased. But no worries, I fixed it on the dev branch.

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

Successfully merging this pull request may close these issues.

2 participants