Skip to content

Don't check board version if device is not connected#1240

Merged
microbit-matt-hillsdon merged 1 commit intomainfrom
check-connected
Apr 30, 2026
Merged

Don't check board version if device is not connected#1240
microbit-matt-hillsdon merged 1 commit intomainfrom
check-connected

Conversation

@microbit-grace
Copy link
Copy Markdown
Contributor

@microbit-grace microbit-grace commented Apr 30, 2026

Since upgrading the connection library, getBoardVersion throws "Not connected" error if micro:bit is not connected. In this case, we only want to check the board version to warn users of v2-only features when a micro:bit is connected.

To repro issue, open https://python.microbit.org/v/beta, then drag and drop v2-only code snippet, such as a data logging code snippet. See error thrown in devtools console.

Since upgrading the connection library, getBoardVersion throws "Not connected" error if micro:bit is not connected. In this case, we only want to check the board version to warn users of v2-only APIs when the micro:bit is connected.
@github-actions
Copy link
Copy Markdown

Preview build will be at
https://review-python-editor-v3.microbit.org/check-connected/

Copy link
Copy Markdown
Collaborator

@microbit-matt-hillsdon microbit-matt-hillsdon left a comment

Choose a reason for hiding this comment

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

OK so one interesting aspect, we do cache after connection, at which point arguably we know which micro:bit you have even if you subsequently disconnect it. So perhaps this code would be better off error handling, to benefit from the caching? WDTY? Maybe:

  let boardVersion: BoardVersion | undefined;
  try {
    boardVersion = device.getBoardVersion();
  } catch {
    // No device has ever been connected (or post clearDevice).
  }
  if (
    code === reportMicrobitVersionApiUnsupported &&
    (!warnOnV2OnlyFeatures || boardVersion !== "V1")
  ) {
    return undefined;
  }

Claude agrees there are no other unguarded connection calls that throw.

@microbit-grace
Copy link
Copy Markdown
Contributor Author

microbit-grace commented Apr 30, 2026

Had a play and I think that the UX is slightly better. It means that the V2-only warnings don't disappear suddenly when the user unplugs/disconnect their V1 micro:bit. If the user do find the warnings annoying because they have mistakenly plugged in their V1 and are intending to use the program for V2, they can "Disable warnings about V2-only features".

However, this change in behaviour might mean changing the copy in the settings dialog:

Screenshot 2026-04-30 at 15 48 51

New copy along the lines of "Warnings are shown in the editor when a micro:bit V1 has been last connected"

@microbit-matt-hillsdon
Copy link
Copy Markdown
Collaborator

Ah, I hadn't really twigged that the new approach matches the old behaviour, I was worried we'd made it worse in this respect. I don't think this is really worth changing copy for. Merging as is.

@microbit-matt-hillsdon microbit-matt-hillsdon merged commit b1c5d1c into main Apr 30, 2026
2 checks passed
@microbit-matt-hillsdon microbit-matt-hillsdon deleted the check-connected branch April 30, 2026 15:01
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