fix: revert remaining ?? '' patterns across Utils, WABinary, Signal, and WAUSync files

Completes the comprehensive revert of defensive null coalescing patterns
introduced in PRs 124-129. These patterns (e.g. `value ?? ''`) silently
produced empty strings instead of failing fast, causing subtle bugs like
malformed JIDs and broken Signal session lookups.

Files: libsignal.ts, messages-recv.ts, chat-utils.ts, generics.ts,
history.ts, messages-media.ts, messages.ts, process-message.ts,
validate-connection.ts, jid-utils.ts, UsyncBotProfileProtocol.ts

https://claude.ai/code/session_01XaA7GwNaB6azTHFYQ8WEpB
This commit is contained in:
Claude
2026-02-09 13:56:33 +00:00
parent 48b63565b6
commit 2a9d9a0a52
11 changed files with 61 additions and 64 deletions
+5 -5
View File
@@ -317,7 +317,7 @@ export const getStream = async (item: WAMediaUpload, opts?: RequestInit & { maxC
const urlStr = item.url.toString()
if (urlStr.startsWith('data:')) {
const buffer = Buffer.from(urlStr.split(',')[1] ?? '', 'base64')
const buffer = Buffer.from(urlStr.split(',')[1]!, 'base64')
return { stream: toReadable(buffer), type: 'buffer' } as const
}
@@ -532,7 +532,7 @@ export const downloadContentFromMessage = async (
opts: MediaDownloadOptions = {}
) => {
const isValidMediaUrl = url?.startsWith('https://mmg.whatsapp.net/')
const downloadUrl = isValidMediaUrl ? url : getUrlFromDirectPath(directPath ?? '')
const downloadUrl = isValidMediaUrl ? url : getUrlFromDirectPath(directPath!)
if (!downloadUrl) {
throw new Boom('No valid media URL or directPath present in message', { statusCode: 400 })
}
@@ -656,7 +656,7 @@ export function extensionForMediaMessage(message: WAMessageContent) {
extension = '.jpeg'
} else {
const messageContent = message[type] as WAGenericMediaMessage
extension = getExtension(messageContent.mimetype ?? '') ?? ''
extension = getExtension(messageContent.mimetype!)!
}
return extension
@@ -864,8 +864,8 @@ export const getWAUploadToServer = (
if (result?.url || result?.direct_path) {
urls = {
mediaUrl: result.url ?? '',
directPath: result.direct_path ?? '',
mediaUrl: result.url!,
directPath: result.direct_path!,
meta_hmac: result.meta_hmac,
fbid: result.fbid,
ts: result.ts