Explain oversized private-message failures

This commit is contained in:
Taksh 2026-11-13 15:50:11 +05:30
parent 8a388eaf41
commit 3eb2df004e
5 changed files with 206 additions and 9 deletions

View File

@ -52221,6 +52221,192 @@
}
}
},
"content.delivery.reason.too_long" : {
"comment" : "Failure reason when a private message exceeds the wire size limit",
"extractionState" : "manual",
"localizations" : {
"ar" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "الرسالة طويلة جدًا"
}
},
"bn" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "বার্তাটি খুব দীর্ঘ"
}
},
"de" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "nachricht zu lang"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "message too long"
}
},
"es" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "mensaje demasiado largo"
}
},
"fa" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "پیام بیش از حد طولانی است"
}
},
"fil" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "masyadong mahaba ang mensahe"
}
},
"fr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "message trop long"
}
},
"he" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "ההודעה ארוכה מדי"
}
},
"hi" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "संदेश बहुत लंबा है"
}
},
"id" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "pesan terlalu panjang"
}
},
"it" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "messaggio troppo lungo"
}
},
"ja" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "メッセージが長すぎます"
}
},
"ko" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "메시지가 너무 깁니다"
}
},
"ms" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "mesej terlalu panjang"
}
},
"ne" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "सन्देश धेरै लामो छ"
}
},
"nl" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "bericht te lang"
}
},
"pl" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "wiadomość jest za długa"
}
},
"pt" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "mensagem demasiado longa"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "mensagem muito longa"
}
},
"ru" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "сообщение слишком длинное"
}
},
"sv" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "meddelandet är för långt"
}
},
"ta" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "செய்தி மிகவும் நீளமாக உள்ளது"
}
},
"th" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "ข้อความยาวเกินไป"
}
},
"tr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "mesaj çok uzun"
}
},
"uk" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "повідомлення надто довге"
}
},
"ur" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "پیغام بہت لمبا ہے"
}
},
"vi" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "tin nhắn quá dài"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "消息过长"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "訊息過長"
}
}
}
},
"content.delivery.reason.unknown_recipient" : {
"extractionState" : "manual",
"localizations" : {

View File

@ -531,7 +531,7 @@ final class CommandProcessor {
if let peerID = contextProvider?.selectedPrivateChatPeer {
guard PrivateMessagePacket.contentFitsOnWire(token) else {
return .error(message: String(localized: "content.delivery.reason.send_error", defaultValue: "send error", comment: "Failure reason for a generic send error"))
return .error(message: String(localized: "content.delivery.reason.too_long", defaultValue: "message too long", comment: "Failure reason when a private message exceeds the wire size limit"))
}
contextProvider?.sendPrivateMessage(token, to: peerID)
return .success(message: String(format: String(localized: "command.pay.sent_private", defaultValue: "sent %@ — cashu is a bearer token; whoever redeems it first gets the funds", comment: "Confirmation after sending a cashu token in a private chat; placeholder is the amount summary"), locale: .current, summary))

View File

@ -397,7 +397,7 @@ final class ChatPrivateConversationCoordinator {
private func initialDeliveryStatus(for content: String) -> DeliveryStatus {
guard PrivateMessagePacket.contentFitsOnWire(content) else {
return .failed(reason: String(localized: "content.delivery.reason.send_error", comment: "Failure reason for a generic send error"))
return .failed(reason: String(localized: "content.delivery.reason.too_long", defaultValue: "message too long", comment: "Failure reason when a private message exceeds the wire size limit"))
}
return .sending
}

View File

@ -1253,11 +1253,20 @@ struct ChatPrivateConversationCoordinatorContextTests {
coordinator.sendPrivateMessage(content, to: peerID)
#expect(context.privateChats[peerID]?.map(\.content) == [content])
guard case .failed? = context.privateChats[peerID]?.first?.deliveryStatus else {
Issue.record("Expected oversized content to fail delivery")
return
}
#expect(context.privateChats[peerID]?.first?.deliveryStatus == .failed(
reason: String(localized: "content.delivery.reason.too_long", defaultValue: "message too long")
))
#expect(context.routedPrivateMessages.isEmpty)
#expect(context.geoPrivateMessages.isEmpty)
// The multibyte UTF-8 boundary still sends: 127 × 2 + 1 = 255 bytes.
let boundaryContent = String(repeating: "é", count: 127) + "a"
#expect(boundaryContent.utf8.count == PrivateMessagePacket.maxContentUTF8Bytes)
coordinator.sendPrivateMessage(boundaryContent, to: peerID)
#expect(context.privateChats[peerID]?.map(\.content) == [content, boundaryContent])
#expect(context.privateChats[peerID]?.last?.deliveryStatus == (isGeohash ? .sent : .sending))
#expect(context.routedPrivateMessages.map(\.content) == (isGeohash ? [] : [boundaryContent]))
#expect(context.geoPrivateMessages.map(\.content) == (isGeohash ? [boundaryContent] : []))
}
}

View File

@ -489,16 +489,18 @@ struct CommandProcessorTests {
}
@MainActor
@Test func payRefusesAPrivateTokenThatDoesNotFitTheWire() {
@Test(arguments: [false, true]) func payRefusesAPrivateTokenThatDoesNotFitTheWire(isGeohash: Bool) {
let context = MockCommandContextProvider()
context.selectedPrivateChatPeer = PeerID(str: "abcd1234abcd1234")
context.selectedPrivateChatPeer = isGeohash
? PeerID(nostr_: String(repeating: "a", count: 64))
: PeerID(str: "abcd1234abcd1234")
let processor = makePayProcessor(context: context)
let token = Self.cashuV3Token(mint: "https://mint.example.com/" + String(repeating: "a", count: 240))
#expect(token.utf8.count > PrivateMessagePacket.maxContentUTF8Bytes)
switch processor.process("/pay \(token)") {
case .error(let message):
#expect(message == "send error")
#expect(message == String(localized: "content.delivery.reason.too_long", defaultValue: "message too long"))
default:
Issue.record("Expected the oversized token to be refused")
}