-
Notifications
You must be signed in to change notification settings - Fork 133
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
Prevent keyNotFound error with unknown simulators #261
base: main
Are you sure you want to change the base?
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! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how best to achieve this, feel free to make any changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MattKiazyk can you please give an update on how you would like to proceed here?
@@ -90,6 +88,9 @@ public class RuntimeInstaller { | |||
} | |||
} | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this vs having the original Unknown
👍
@@ -108,18 +108,18 @@ extension DownloadableRuntime { | |||
} | |||
|
|||
public struct InstalledRuntime: Decodable { | |||
let build: String | |||
let build: String? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#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 runtimes
when an "Unknown Platform Simulator" is installed:If one accidentally runs
xcrun simctl runtime add
with 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 nobuild
key resulting in the error:This change results in the following
xcodes runtimes
output:Another approach could be to filter out undecodable runtimes in the
RuntimeList
class, this actually resulted in more code though.