Don't check board version if device is not connected#1240
Merged
microbit-matt-hillsdon merged 1 commit intomainfrom Apr 30, 2026
Merged
Don't check board version if device is not connected#1240microbit-matt-hillsdon merged 1 commit intomainfrom
microbit-matt-hillsdon merged 1 commit intomainfrom
Conversation
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.
|
Preview build will be at |
Collaborator
There was a problem hiding this comment.
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.
Contributor
Author
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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.