Skip to content

Remove crashing assertions #41

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
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Sources/WebMIDIKit/MIDIPortMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class MIDIPortMap<Value: MIDIPort>: Collection {
if port.isVirtual {
return self[port.id]!
} else {
assert(self[port.id] == nil)
assert(self[port.id] == nil, "Port with ID \(port.id) should not exist, yet")
self[port.id] = port
return port
}
Expand All @@ -66,8 +66,7 @@ public class MIDIPortMap<Value: MIDIPort>: Collection {

internal final func remove(_ endpoint: MIDIEndpoint) -> Value? {
// disconnect?
guard let port = self[endpoint] else { assert(false); return nil }
assert(port.state == .connected)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adamnemecek Since nothing bad happens when the state is not .connected, removing this wasn't a problem. But I think we could add an if port.state == connected path here if cleanup and disconnecting would be required.

guard let port = self[endpoint] else { return nil }
self[port.id] = nil
return port
}
Expand Down