DDP `encodeResult` drops falsy method return values (`false`, `0`, `""`, `null`)

Aperta Adatta ai principianti
#43,925 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Arnav-0206 ci sta già lavorando.

Dal 25/11/2026.

  • #43927 di @Arnav-0206 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
backend

Direzione di ricerca

Il bug si trova in encodeResult in packages/ddp-server/src/codec.ts, che verifica il risultato con un controllo di valore truthy invece di confrontarlo con undefined, e nel blocco catch di Server.call in packages/ddp-server/src/Server.ts, che passa null dove dovrebbe esserci undefined. Inizia leggendo entrambi i punti, poi esegui codec.spec.ts e Server.spec.ts, dove i nuovi casi con valori falsy già falliscono. È completato quando questi 12 casi passano e i frame di errore continuano a omettere il campo result.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

type: bug
Description:

When a DDP method handled by @rocket.chat/ddp-server returns false, 0, "", or null, the result field is left out of the wire packet ({"msg":"result","id":"..."}), so the client gets undefined instead of the actual return value.

In packages/ddp-server/src/codec.ts, encodeResult checks ...(result && { result }) instead of checking against undefined. Meanwhile, the catch block in Server.call (packages/ddp-server/src/Server.ts) passes null instead of undefined when sending an error, which only worked because null was falsy.

Steps to reproduce:
  1. Call encodeResult('m1', false) (or invoke any local/remote method through Server.call that resolves to false, 0, "", or null).
  2. Decode the serialized DDP result message.
Expected behavior:

Non-error result frames keep "result" for false, 0, "", and null, and omit result only when the return value is undefined or when error is present.

Actual behavior:

result is omitted completely ({"msg":"result","id":"m1"}), so callers receive undefined.

Server Setup Information:
  • Version of Rocket.Chat Server: 9.2.0-develop
  • License Type: Community
  • Number of Users: 1
  • Operating System: Ubuntu (WSL 2)
  • Deployment Method: Local development (yarn dsv)
  • Number of Running Instances: 1
  • DB Replicaset Oplog: Enabled
  • NodeJS Version: v24.15.0
  • MongoDB Version: 8.0
Client Setup Information
  • Desktop App or Browser Version: N/A (DDP WebSocket / @rocket.chat/ddp-server)
  • Operating System: Ubuntu (WSL 2) / Windows
Additional context

This only affects @rocket.chat/ddp-server (encodeResult and Server.call). HTTP-bridged calls under /api/v1/method.call and method.callAnon use EJSON.stringify({ msg: 'result', id, error, result }) and already keep falsy values.

Relevant logs:

Added unit test cases for false, 0, "", and null in packages/ddp-server/src/codec.spec.ts and packages/ddp-server/src/Server.spec.ts — all 12 new cases fail on 9.2.0-develop because result is missing from the decoded DDP packet.

Lingua principale
TypeScript
Stelle
46.6k
Fork
14.2k
Merge medio
2g 21h
PR unite (30g)
302

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di RocketChat/Rocket.Chat

Tutte le issue di RocketChat/Rocket.Chat

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.