denoland/deno · error · TypeError

ERR_MISSING_ARGS

ERR_MISSING_ARGS

Error message

The "multicastAddress" argument must be specified

What it means

dgram Socket.addMembership(multicastAddress, interfaceAddress?) requires a truthy multicast group address; an empty string or missing value throws ERR_MISSING_ARGS before the kernel join (IP_ADD_MEMBERSHIP) is attempted. Note the check is falsiness-based, not format-based — a malformed non-empty string will fail later in addMembership with an errno exception instead.

Source

Thrown at ext/node/polyfills/dgram.ts:293

   * import cluster from "ext:deno_node/cluster";
   * import dgram from "ext:deno_node/dgram";
   *
   * if (cluster.isPrimary) {
   *   cluster.fork(); // Works ok.
   *   cluster.fork(); // Fails with EADDRINUSE.
   * } else {
   *   const s = dgram.createSocket('udp4');
   *   s.bind(1234, () => {
   *     s.addMembership('224.0.0.114');
   *   });
   * }
   * ```
   */
  addMembership(multicastAddress: string, interfaceAddress?: string) {
    healthCheck(this);

    if (!multicastAddress) {
      throw new ERR_MISSING_ARGS("multicastAddress");
    }

    const { handle } = this[kStateSymbol];
    const err = handle!.addMembership(multicastAddress, interfaceAddress);

    if (err) {
      throw errnoException(err, "addMembership");
    }
  }

  /**
   * Tells the kernel to join a source-specific multicast channel at the given
   * `sourceAddress` and `groupAddress`, using the `multicastInterface` with
   * the `IP_ADD_SOURCE_MEMBERSHIP` socket option. If the `multicastInterface`
   * argument is not specified, the operating system will choose one interface
   * and will add membership to it. To add membership to every available
   * interface, call `socket.addSourceSpecificMembership()` multiple times,
   * once per interface.

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Pass a valid IPv4 multicast group such as '224.0.0.114' (range 224.0.0.0-239.255.255.255)
  2. Validate and default the configured address once at startup
  3. Join inside the 'listening' event callback, where config is final and the socket is bound

Example fix

// before
sock.addMembership(process.env.MC_GROUP);
// after
sock.addMembership(process.env.MC_GROUP ?? "224.0.0.114");
Defensive patterns

Strategy: validation

Validate before calling

function isIpv4Multicast(addr) {
  if (typeof addr !== "string" || addr === "") return false;
  const o = addr.split(".").map(Number);
  return o.length === 4 && o.every((n) => Number.isInteger(n) && n >= 0 && n <= 255) &&
    o[0] >= 224 && o[0] <= 239;
}
const group = process.env.MC_GROUP;
if (!isIpv4Multicast(group)) throw new Error(`valid multicast address required, got ${group}`);
sock.addMembership(group);

Type guard

const isMulticastAddress = (a) => typeof a === "string" && a !== "";

Try / catch

try { sock.addMembership(group); }
catch (e) {
  if (e.code === "ERR_MISSING_ARGS") { /* group not configured; skip join */ }
  else throw e;
}

Prevention

When it happens

Trigger: sock.addMembership('') or addMembership(undefined); the group address read from an env var that is unset in this deployment; calling addMembership before configuration finished loading.

Common situations: Multicast group from environment (e.g. MC_GROUP) missing in staging/production; shared helpers that assume a default group; config parsed after the socket already starts listening.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/b382885b6f8b656f. Report an issue: GitHub.