paulober / MicroPico

MicroPico (aka Pico-W-Go) is a Visual Studio Code extension designed to simplify and speed up the development of MicroPython projects for the Raspberry Pi Pico and Pico W boards.
https://marketplace.visualstudio.com/items?itemName=paulober.pico-w-go
Mozilla Public License 2.0
279 stars 25 forks source link

Switch Stubs resulted in an error #227

Closed wtakuo closed 3 months ago

wtakuo commented 3 months ago

Please provide a clear and concise description of the bug along with logs

What are the steps to reproduce this issue?

  1. Start command "MicroPico:Extra > Switch stubs"
  2. In "Select the stubs port you want to use" menu, choose an arbitrary port other than "Included"
  3. In "Select the stubs version you want to use" menu, choose an arbitrary version

What happens?

What were you expecting to happen?

For example, if we select port ESP32 version 1.23.0.post1, the following error dialog will appear. Similar results are obtained for the other combinations.

Screenshot_2024-06-21 0 10 31

Any logs, error output, etc?

(To get extension logs see Terminal > Output > Extension Host and copy output concerning pico-w-go or micropico) (If it’s long, please paste to https://gist.github.com and insert the link here)

024-06-21 23:53:04.043 [error] Error: Command failed: "/Users/takuo/.pyenv/shims/pip3" install 1.23.0.post1==undefined --target "/Users/takuo/.micropico-stubs/1.23.0.post1==undefined" --no-user
ERROR: Could not find a version that satisfies the requirement 1.23.0.post1==undefined (from versions: none)
ERROR: No matching distribution found for 1.23.0.post1==undefined

    at checkExecSyncError (node:child_process:928:11)
    at Object.execSync (node:child_process:1000:15)
    at Object.execSync (node:electron/js2c/node_init:2:13035)
    at installStubsByVersion (/Users/takuo/local/src/MicroPico/src/stubs.mts:336:18)
    at /Users/takuo/local/src/MicroPico/src/activator.mts:1156:30 micropico.extra.switchStubs {"value":"paulober.pico-w-go","_lower":"paulober.pico-w-go"}

Any other comments?

Perhaps the cause is that in the following code (activator.mts, lines 1121-1130), the value of Object.keys( availableStubVersions).length is always 1 because the type of availableStubVersions is {[key: string]: string[]}.

          Object.entries(availableStubVersions).forEach(([key, values]) => {
            // Map each value to "key - value" and push to resultArray
            versions.push(
              ...values.map(value =>
                Object.keys(availableStubVersions).length > 1
                  ? `${stubPortToDisplayString(key)} - ${value}`
                  : value
              )
            );
          });

This causes versions to be just a list of version number strings, and in the following code (activator.mts, line 1152), versionParts is set to a different value than expected.

              const versionParts = version.split(" - ");

The above code can be changed as follows to achieve the expected behavior.

          Object.entries(availableStubVersions).forEach(([key, values]) => {
            // Map each value to "key - value" and push to resultArray
            versions.push(
              ...values.map(value =>
                `${stubPortToDisplayString(key)} - ${value}`
              )
            );
          });

Which version of MicroPico are you using?

3.7.8

Support info

Copy this from the Help -> Info/About -> Copy (Code -> About Visual Studio Code -> Copy on macOS) option in Visual Studio Code:

Version: 1.90.2 (Universal)
Commit: 5437499feb04f7a586f677b155b039bc2b3669eb
Date: 2024-06-18T22:37:41.291Z
Electron: 29.4.0
ElectronBuildId: 9728852
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Darwin arm64 23.5.0
paulober commented 3 months ago

@wtakuo Thanks for taking the time to report this bug in this very detailed issue and providing a PR to fix it ASAP. I'm sorry that you had this bug, it should have definitely get caught during testing. I'll include your fix in the next patch which will be released today.