Skip to content

Commit a77c7fa

Browse files
authored
Merge pull request #127 from xmtp/jazz/contact-bundle-error-handling
fix: return clearer error on ContactBundle decode faliure
2 parents 8d5476f + 666e95e commit a77c7fa

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/ContactBundle.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ export default class ContactBundle implements proto.ContactBundleV1 {
1414
}
1515

1616
toBytes(): Uint8Array {
17-
return proto.ContactBundleV1.encode({
18-
keyBundle: this.keyBundle,
19-
}).finish()
17+
return this.keyBundle.toBytes()
2018
}
2119

2220
static fromBytes(bytes: Uint8Array): ContactBundle {
@@ -49,11 +47,13 @@ export default class ContactBundle implements proto.ContactBundleV1 {
4947
e instanceof RangeError ||
5048
(e instanceof Error && e.message.startsWith('invalid wire type'))
5149
) {
52-
// Adds a default fallback for older versions of the proto
53-
const legacyBundle = proto.ContactBundleV1.decode(bytes)
54-
return legacyBundle.keyBundle
50+
// Adds a default fallback for older versions of the proto (Which may also fail)
51+
try {
52+
return proto.PublicKeyBundle.decode(bytes)
53+
} catch (e) {
54+
throw new Error("Couldn't decode contact bundle: " + e)
55+
}
5556
}
56-
throw new Error("Couldn't decode contact bundle:" + e)
5757
}
5858
}
5959
}

0 commit comments

Comments
 (0)