Add description for generic ConnectionProfile

This commit is contained in:
Davide De Rosa 2018-11-04 15:56:05 +01:00
parent 2923991372
commit 137e87ad69
2 changed files with 10 additions and 4 deletions

View File

@ -33,7 +33,7 @@ enum Context: String, Codable {
case host case host
} }
protocol ConnectionProfile: class, EndpointDataSource { protocol ConnectionProfile: class, EndpointDataSource, CustomStringConvertible {
var context: Context { get } var context: Context { get }
var id: String { get } var id: String { get }
@ -80,3 +80,9 @@ extension ConnectionProfile {
keychain.removePassword(for: key) keychain.removePassword(for: key)
} }
} }
extension ConnectionProfile {
var description: String {
return "[\(context):\(id)]"
}
}

View File

@ -253,7 +253,7 @@ class ConnectionService: Codable {
} else if let hostProfile = profile as? HostConnectionProfile { } else if let hostProfile = profile as? HostConnectionProfile {
optData = try encoder.encode(hostProfile) optData = try encoder.encode(hostProfile)
} else if let placeholder = profile as? PlaceholderConnectionProfile { } else if let placeholder = profile as? PlaceholderConnectionProfile {
log.debug("Skipped \(placeholder.context) '\(placeholder.id)'") log.debug("Skipped placeholder \(placeholder)")
} else { } else {
fatalError("Attempting to add an unhandled profile type: \(type(of: profile))") fatalError("Attempting to add an unhandled profile type: \(type(of: profile))")
} }
@ -261,9 +261,9 @@ class ConnectionService: Codable {
return return
} }
try data.write(to: url) try data.write(to: url)
log.debug("Serialized \(profile.context) profile '\(profile.id)'") log.debug("Serialized profile \(profile)")
} catch let e { } catch let e {
log.warning("Could not serialize \(profile.context) profile '\(profile.id)': \(e)") log.warning("Could not serialize profile \(profile): \(e)")
} }
} }