Prevent keyNotFound error with unknown simulators#261
Prevent keyNotFound error with unknown simulators#261dnicolson wants to merge 4 commits intoXcodesOrg:mainfrom
Conversation
|
Nice catch, thank you :)
I prefer that approach. it doesn't have to be a lot of code, actually, it's less code. Remove all the installed runtimes with the state I would also add a note at the end with how many unknown runtimes were found, with a suggestion to run Disclaimer: I contributed the runtimes feature but I'm not part of the team, so you might want to wait for their opinion/review. |
|
The amount of unknown runtimes is indicated by how many "Unknown" runtimes are listed, it should be comparable to what is in Xcode. It's not ideal that there is a The original approach seemed to require using a custom decoder and possibly filtering out the items unable to be decoded afterward. Or do you mean keeping the optional keys so that the decoding doesn't fail? |
yeah, what i meant is removing the and replacing it at the end with (if more than 0): you just have to add |
|
I've made those changes, thanks for the input! |
MattKiazyk
left a comment
There was a problem hiding this comment.
Thanks for adding this @dnicolson 🎉
Can we remove the force unwraps? As well as add a quick test for these? Let me know if you need some help.
| installed.forEach { runtime in | ||
| let resolvedBetaNumber = downloadablesResponse.sdkToSeedMappings.first { | ||
| $0.buildUpdate == runtime.build | ||
| $0.buildUpdate == runtime.build! |
There was a problem hiding this comment.
Can we refactor this section a bit?
Can we not use force unwrap. As a rule, I don't use them. Totally agree that it should never happen but it's bitten me in the past. Perhaps making an overloaded PrintableRuntime() to allow optionals?
There was a problem hiding this comment.
I'm not sure how best to achieve this, feel free to make any changes.
There was a problem hiding this comment.
Just my 2 cents here, personally I also try to avoid them if I can, but in this case, I would prefer a force unwrap to fail than hiding the error and providing an empty string as a default value, in that case, we would know that xcrun simctl runtime list printed something that we didn't account for, and there is probably a new state of a runtime that we should write code for. I see it as a assert/precondition and not a code smell.
There was a problem hiding this comment.
@MattKiazyk can you please give an update on how you would like to proceed here?
| } | ||
| } | ||
| Current.logging.log("\nNote: Bundled runtimes are indicated for the currently selected Xcode, more bundled runtimes may exist in other Xcode(s)") | ||
| if unusableCount > 0 { |
There was a problem hiding this comment.
I like this vs having the original Unknown 👍
|
|
||
| public struct InstalledRuntime: Decodable { | ||
| let build: String | ||
| let build: String? |
There was a problem hiding this comment.
#picky can we add a comment on why these are optional
|
Hi, is there any updates for this PR? |
|
@MattKiazyk can you please give an update? |
This pull request prevents the following error when running
xcodes runtimeswhen an "Unknown Platform Simulator" is installed:If one accidentally runs
xcrun simctl runtime addwith an incompatible pre-iOS 16 Simulator runtime:The following error will be displayed:
The problem is that it's not immediately obvious that Xcode has still installed the runtime, but with a missing signature state:

And when xcodes runs
xcrun simctl runtime list -j, there is nobuildkey resulting in the error:This change results in the following
xcodes runtimesoutput:Another approach could be to filter out undecodable runtimes in the
RuntimeListclass, this actually resulted in more code though.