fix(dm): clear error when contact not on device, log error_code detail

Device firmware requires contacts in its table to send DMs. Passing
a raw pubkey string results in error_code=2. Show actionable error
message instead of generic "Device error".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2026-03-07 07:32:56 +01:00
parent 6a5fe98e32
commit 1a3a1e937c
+5 -4
View File
@@ -827,14 +827,15 @@ class DeviceManager:
return {'success': False, 'error': 'Device not connected'}
try:
# Find contact dict from mc.contacts (used for retry/path info)
# send_msg() also accepts a hex pubkey string directly
# Find contact in device's contact table
contact = self.mc.contacts.get(recipient_pubkey)
if not contact:
contact = self.mc.get_contact_by_key_prefix(recipient_pubkey)
if not contact:
# Use pubkey string directly — meshcore lib handles it
contact = recipient_pubkey
# Contact must exist on device to send DM
return {'success': False,
'error': f'Contact not on device. '
f'Re-add {recipient_pubkey[:12]}... via Contacts page.'}
# Generate timestamp once — same for all retries (enables receiver dedup)
timestamp = int(time.time())