Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Prevent keyNotFound error with unknown simulators #261

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

Open
dnicolson wants to merge 4 commits into XcodesOrg:main
base: main
Choose a base branch
Loading
from dnicolson:fix-keynotfound-error

Conversation

@dnicolson
Copy link

@dnicolson dnicolson commented Jan 4, 2023

This pull request prevents the following error when running xcodes runtimes when an "Unknown Platform Simulator" is installed:

Error: keyNotFound(CodingKeys(stringValue: "build", intValue: nil), Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "820783CB-C389-4006-B2D2-D063F3FD10A1", intValue: nil)], debugDescription: "No value associated with key CodingKeys(stringValue: \"build\", intValue: nil) (\"build\").", underlyingError: nil))

If one accidentally runs xcrun simctl runtime add with an incompatible pre-iOS 16 Simulator runtime:

xcrun simctl runtime add com.apple.pkg.iPhoneSimulatorSDK15_0-15.0.1.1633542405.dmg

The following error will be displayed:

D: 94DEF0B1-1585-4D71-AB37-98AB08FDD000 <unknown platform> (Unusable - Missing Signature: Error Domain=SimDiskImageErrorDomain Code=3 "Missing Signature" UserInfo={NSLocalizedDescription=Missing Signature, unusableErrorDetail=})

The problem is that it's not immediately obvious that Xcode has still installed the runtime, but with a missing signature state:
PixelSnap 2023年01月04日 at 07 50 16@2x

And when xcodes runs xcrun simctl runtime list -j, there is no build key resulting in the error:

"820783CB-C389-4006-B2D2-D063F3FD10A1" : {
 "deletable" : true,
 "identifier" : "820783CB-C389-4006-B2D2-D063F3FD10A1",
 "kind" : "Disk Image",
 "path" : "\/Library\/Developer\/CoreSimulator\/Images\/Inbox\/820783CB-C389-4006-B2D2-D063F3FD10A1.dmg",
 "signatureState" : "Missing",
 "sizeBytes" : 5304795932,
 "state" : "Unusable",
 "unusableErrorDetail" : "Error Domain=SimDiskImageErrorDomain Code=3 \"Missing Signature\" UserInfo={NSLocalizedDescription=Missing Signature, unusableErrorDetail=}",
 "unusableErrorMessage" : "Missing Signature",
 "unusableSubstate" : "Missing Signature"
}

This change results in the following xcodes runtimes output:

-- Unknown --
Unknown 0 (Downloaded)

Another approach could be to filter out undecodable runtimes in the RuntimeList class, this actually resulted in more code though.

@dnicolson dnicolson requested a review from a team as a code owner January 4, 2023 07:27
Copy link
Contributor

Nice catch, thank you :)

Another approach could be to filter out undecodable runtimes in the RuntimeList class, this actually resulted in more code though.

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 unusable, before looping over them, then you can then force-unwrap build, version, and platformIdentifier (and remove the unknown enum case).

I would also add a note at the end with how many unknown runtimes were found, with a suggestion to run xcrun simctl runtime list -j for more info.

Disclaimer: I contributed the runtimes feature but I'm not part of the team, so you might want to wait for their opinion/review.

Copy link
Author

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 0 though, but further hacks wouldn't have been nice.

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?

Copy link
Contributor

Or do you mean keeping the optional keys so that the decoding doesn't fail?

yeah, what i meant is removing the

-- Unknown --
Unknown 0 (Downloaded)

and replacing it at the end with (if more than 0):

Note: Found 1 unknown downloaded runtime(s). For more info run `xcrun simctl runtime list -j`.

you just have to add let unusableCount = installed.removeAll { 0ドル.state == "Unusable" }.count before looping over the installed array, and then you can force-unwrap the newly optional values.

Copy link
Author

I've made those changes, thanks for the input!

StevenSorial reacted with thumbs up emoji

Copy link
Contributor

@MattKiazyk MattKiazyk left a 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!
Copy link
Contributor

@MattKiazyk MattKiazyk Jan 6, 2023

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?

Copy link
Author

@dnicolson dnicolson Jan 6, 2023

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.

Copy link
Contributor

@StevenSorial StevenSorial Jan 8, 2023

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.

Copy link
Author

@dnicolson dnicolson Apr 2, 2023

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?

}
}
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 {
Copy link
Contributor

@MattKiazyk MattKiazyk Jan 6, 2023

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 👍


public struct InstalledRuntime: Decodable {
let build: String
let build: String?
Copy link
Contributor

@MattKiazyk MattKiazyk Jan 6, 2023

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

Copy link

Hi, is there any updates for this PR?

Copy link
Author

@MattKiazyk can you please give an update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@MattKiazyk MattKiazyk MattKiazyk requested changes

+1 more reviewer

@StevenSorial StevenSorial StevenSorial left review comments

Reviewers whose approvals may not affect merge requirements

Requested changes must be addressed to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /