Updated the invalid config errors to include the pubkey for debugging

pull/1061/head
Morgan Pretty 2 months ago
parent a080d67618
commit cd919284f0

@ -29,7 +29,7 @@ internal extension LibSessionCacheType {
guard groupState[.groupKeys] != nil && groupState[.groupInfo] != nil && groupState[.groupMembers] != nil else {
Log.error(.libSession, "Group config objects were null")
throw LibSessionError.unableToCreateConfigObject
throw LibSessionError.unableToCreateConfigObject(groupSessionId.hexString)
}
groupState.forEach { variant, config in
@ -80,7 +80,7 @@ internal extension LibSession {
// Extract the conf objects from the state to load in the initial data
guard case .groupKeys(let groupKeysConf, let groupInfoConf, let groupMembersConf) = groupState[.groupKeys] else {
Log.error(.libSession, "Group config objects were null")
throw LibSessionError.unableToCreateConfigObject
throw LibSessionError.unableToCreateConfigObject(groupSessionId.hexString)
}
// Set the initial values in the confs
@ -219,7 +219,7 @@ internal extension LibSession {
nil,
0,
&error
).orThrow(error: error)
).orThrow(error: error, groupSessionId: groupSessionId)
try groups_members_init(
&groupMembersConf,
&groupIdentityPublicKey,
@ -227,7 +227,7 @@ internal extension LibSession {
nil,
0,
&error
).orThrow(error: error)
).orThrow(error: error, groupSessionId: groupSessionId)
try groups_keys_init(
&groupKeysConf,
@ -239,7 +239,7 @@ internal extension LibSession {
nil,
0,
&error
).orThrow(error: error)
).orThrow(error: error, groupSessionId: groupSessionId)
case .none:
try groups_info_init(
@ -249,7 +249,7 @@ internal extension LibSession {
nil,
0,
&error
).orThrow(error: error)
).orThrow(error: error, groupSessionId: groupSessionId)
try groups_members_init(
&groupMembersConf,
&groupIdentityPublicKey,
@ -257,7 +257,7 @@ internal extension LibSession {
nil,
0,
&error
).orThrow(error: error)
).orThrow(error: error, groupSessionId: groupSessionId)
try groups_keys_init(
&groupKeysConf,
@ -269,7 +269,7 @@ internal extension LibSession {
nil,
0,
&error
).orThrow(error: error)
).orThrow(error: error, groupSessionId: groupSessionId)
}
guard
@ -278,7 +278,7 @@ internal extension LibSession {
let membersConf: UnsafeMutablePointer<config_object> = groupMembersConf
else {
Log.error(.libSession, "Group config objects were null")
throw LibSessionError.unableToCreateConfigObject
throw LibSessionError.unableToCreateConfigObject(groupSessionId.hexString)
}
// Define the config state map and load it into memory
@ -360,11 +360,11 @@ internal extension LibSessionCacheType {
}
private extension Int32 {
func orThrow(error: [CChar]) throws {
func orThrow(error: [CChar], groupSessionId: SessionId) throws {
guard self != 0 else { return }
Log.error(.libSession, "Unable to create group config objects: \(String(cString: error))")
throw LibSessionError.unableToCreateConfigObject
throw LibSessionError.unableToCreateConfigObject(groupSessionId.hexString)
}
}

@ -323,8 +323,8 @@ public extension LibSession {
switch (variant, groupEd25519SecretKey) {
case (.invalid, _):
throw LibSessionError.unableToCreateConfigObject
.logging("Unable to create \(variant.rawValue) config object")
throw LibSessionError.unableToCreateConfigObject(sessionId.hexString)
.logging("Unable to create \(variant.rawValue) config object for: \(sessionId.hexString)")
case (.userProfile, _), (.contacts, _), (.convoInfoVolatile, _), (.userGroups, _):
return try (userConfigInitCalls[variant]?(
@ -334,7 +334,7 @@ public extension LibSession {
(cachedDump?.length ?? 0),
&error
))
.toConfig(conf, variant: variant, error: error)
.toConfig(conf, variant: variant, error: error, sessionId: sessionId)
case (.groupInfo, .some(var adminSecretKey)), (.groupMembers, .some(var adminSecretKey)):
var identityPublicKey: [UInt8] = sessionId.publicKey
@ -347,7 +347,7 @@ public extension LibSession {
(cachedDump?.length ?? 0),
&error
))
.toConfig(conf, variant: variant, error: error)
.toConfig(conf, variant: variant, error: error, sessionId: sessionId)
case (.groupKeys, .some(var adminSecretKey)):
var identityPublicKey: [UInt8] = sessionId.publicKey
@ -356,8 +356,8 @@ public extension LibSession {
case .groupInfo(let infoConf) = configStore[sessionId, .groupInfo],
case .groupMembers(let membersConf) = configStore[sessionId, .groupMembers]
else {
throw LibSessionError.unableToCreateConfigObject
.logging("Unable to create \(variant.rawValue) config object for \(sessionId): Group info and member config states not loaded")
throw LibSessionError.unableToCreateConfigObject(sessionId.hexString)
.logging("Unable to create \(variant.rawValue) config object for \(sessionId), group info \(configStore[sessionId, .groupInfo] != nil ? "loaded" : "not loaded") and member config \(configStore[sessionId, .groupMembers] != nil ? "loaded" : "not loaded")")
}
return try groups_keys_init(
@ -371,7 +371,7 @@ public extension LibSession {
(cachedDump?.length ?? 0),
&error
)
.toConfig(keysConf, info: infoConf, members: membersConf, variant: variant, error: error)
.toConfig(keysConf, info: infoConf, members: membersConf, variant: variant, error: error, sessionId: sessionId)
// It looks like C doesn't deal will passing pointers to null variables well so we need
// to explicitly pass 'nil' for the admin key in this case
@ -386,7 +386,7 @@ public extension LibSession {
(cachedDump?.length ?? 0),
&error
))
.toConfig(conf, variant: variant, error: error)
.toConfig(conf, variant: variant, error: error, sessionId: sessionId)
// It looks like C doesn't deal will passing pointers to null variables well so we need
// to explicitly pass 'nil' for the admin key in this case
@ -397,8 +397,8 @@ public extension LibSession {
case .groupInfo(let infoConf) = configStore[sessionId, .groupInfo],
case .groupMembers(let membersConf) = configStore[sessionId, .groupMembers]
else {
throw LibSessionError.unableToCreateConfigObject
.logging("Unable to create \(variant.rawValue) config object for \(sessionId): Group info and member config states not loaded")
throw LibSessionError.unableToCreateConfigObject(sessionId.hexString)
.logging("Unable to create \(variant.rawValue) config object for \(sessionId), group info \(configStore[sessionId, .groupInfo] != nil ? "loaded" : "not loaded") and member config \(configStore[sessionId, .groupMembers] != nil ? "loaded" : "not loaded")")
}
return try groups_keys_init(
@ -412,7 +412,7 @@ public extension LibSession {
(cachedDump?.length ?? 0),
&error
)
.toConfig(keysConf, info: infoConf, members: membersConf, variant: variant, error: error)
.toConfig(keysConf, info: infoConf, members: membersConf, variant: variant, error: error, sessionId: sessionId)
}
}
@ -1069,10 +1069,11 @@ private extension Optional where Wrapped == Int32 {
func toConfig(
_ maybeConf: UnsafeMutablePointer<config_object>?,
variant: ConfigDump.Variant,
error: [CChar]
error: [CChar],
sessionId: SessionId
) throws -> LibSession.Config {
guard self == 0, let conf: UnsafeMutablePointer<config_object> = maybeConf else {
throw LibSessionError.unableToCreateConfigObject
throw LibSessionError.unableToCreateConfigObject(sessionId.hexString)
.logging("Unable to create \(variant.rawValue) config object: \(String(cString: error))")
}
@ -1084,7 +1085,7 @@ private extension Optional where Wrapped == Int32 {
case .groupInfo: return .groupInfo(conf)
case .groupMembers: return .groupMembers(conf)
case .groupKeys, .invalid: throw LibSessionError.unableToCreateConfigObject
case .groupKeys, .invalid: throw LibSessionError.unableToCreateConfigObject(sessionId.hexString)
}
}
}
@ -1095,16 +1096,17 @@ private extension Int32 {
info: UnsafeMutablePointer<config_object>,
members: UnsafeMutablePointer<config_object>,
variant: ConfigDump.Variant,
error: [CChar]
error: [CChar],
sessionId: SessionId
) throws -> LibSession.Config {
guard self == 0, let conf: UnsafeMutablePointer<config_group_keys> = maybeConf else {
throw LibSessionError.unableToCreateConfigObject
throw LibSessionError.unableToCreateConfigObject(sessionId.hexString)
.logging("Unable to create \(variant.rawValue) config object: \(String(cString: error))")
}
switch variant {
case .groupKeys: return .groupKeys(conf, info: info, members: members)
default: throw LibSessionError.unableToCreateConfigObject
default: throw LibSessionError.unableToCreateConfigObject(sessionId.hexString)
}
}
}

@ -6,7 +6,7 @@ import Foundation
import SessionUtil
public enum LibSessionError: Error, CustomStringConvertible {
case unableToCreateConfigObject
case unableToCreateConfigObject(String)
case invalidConfigObject
case invalidDataProvided
case invalidConfigAccess
@ -117,7 +117,7 @@ public enum LibSessionError: Error, CustomStringConvertible {
public var description: String {
switch self {
case .unableToCreateConfigObject: return "Unable to create config object (LibSessionError.unableToCreateConfigObject)."
case .unableToCreateConfigObject(let pubkey): return "Unable to create config object for: \(pubkey) (LibSessionError.unableToCreateConfigObject)."
case .invalidConfigObject: return "Invalid config object (LibSessionError.invalidConfigObject)."
case .invalidDataProvided: return "Invalid data provided (LibSessionError.invalidDataProvided)."
case .invalidConfigAccess: return "Invalid config access (LibSessionError.invalidConfigAccess)."

Loading…
Cancel
Save