decolua/9router · error · Error

Wrong sudo password | Failed to add DNS entry: ${error.messa

Error message

Wrong sudo password | Failed to add DNS entry: ${error.message}

What it means

After building the new hosts-file content, addDNSEntry() writes it via `tee` through execWithPassword and flushes the DNS cache. On failure it inspects the error: if it mentions 'incorrect password' it throws 'Wrong sudo password', otherwise `Failed to add DNS entry: <detail>`. It normalizes sudo auth failures vs hosts-write/flush failures.

Source

Thrown at src/mitm/dns/dnsConfig.js:178

      const trimmed = current.replace(/[\r\n\s]+$/g, "");
      const toAppend = entriesToAdd.map(h => `127.0.0.1 ${h}`).join("\r\n");
      const next = `${trimmed}\r\n${toAppend}\r\n`;
      atomicWriteHostsWin(HOSTS_FILE, current, next);
      await runElevatedPowerShell("ipconfig /flushdns | Out-Null");
    } else {
      const current = fs.readFileSync(HOSTS_FILE, "utf8");
      const trimmed = current.replace(/[\r\n\s]+$/g, "");
      const toAppend = entriesToAdd.map(h => `127.0.0.1 ${h}`).join("\n");
      const next = `${trimmed}\n${toAppend}\n`;
      // Use tee via sudo to overwrite atomically — escape single quotes in content
      const escaped = next.replace(/'/g, "'\\''");
      await execWithPassword(`printf '%s' '${escaped}' | tee ${HOSTS_FILE} > /dev/null`, sudoPassword);
      await flushDNS(sudoPassword);
    }
    log(`🌐 DNS ${tool}: ✅ added ${entriesToAdd.join(", ")}`);
  } catch (error) {
    const msg = error.message?.includes("incorrect password") ? "Wrong sudo password" : `Failed to add DNS entry: ${error.message}`;
    throw new Error(msg);
  }
}

/**
 * Remove DNS entries for a specific tool
 */
async function removeDNSEntry(tool, sudoPassword) {
  const hosts = TOOL_HOSTS[tool];
  if (!hosts) throw new Error(`Unknown tool: ${tool}`);

  const entriesToRemove = hosts.filter(h => checkDNSEntry(h));
  if (entriesToRemove.length === 0) {
    log(`🌐 DNS ${tool}: already inactive`);
    return;
  }

  try {
    if (IS_WIN) {

View on GitHub (pinned to 90b52e06ff)

Solutions

  1. Re-run with the correct sudo password (verify with `sudo -v`)
  2. Check /etc/hosts is writable by root and not immutable (`lsattr /etc/hosts`)
  3. Verify the DNS flush command exists on this OS/distro
  4. Run from a session where sudo can prompt (TTY available)
  5. Inspect the wrapped error detail after 'Failed to add DNS entry:' for the root cause
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify sudo works before touching /etc/hosts
try {
  await execWithPassword('sudo -v', sudoPassword);
} catch {
  throw new Error('Sudo password invalid; cannot modify /etc/hosts');
}

Try / catch

try {
  await addDNSEntry(tool, sudoPassword);
} catch (e) {
  if (e.message === 'Wrong sudo password') {
    // re-prompt the user for the password and retry once
  } else if (e.message.startsWith('Failed to add DNS entry:')) {
    console.error('hosts write/flush failed:', e.message);
  } else throw e;
}

Prevention

When it happens

Trigger: addDNSEntry() when: the supplied sudoPassword is wrong, sudo auth is canceled, the hosts file (HOSTS_FILE) is not writable even with sudo, tee fails, or the DNS flush command fails.

Common situations: User typed the wrong sudo password in the prompt or stored password changed after an OS password reset; running in a container without a writable /etc/hosts; macOS/Linux DNS flush command unavailable on the distro; sudo TTY requirement in headless sessions.

Related errors


AI-assisted analysis of decolua/9router@90b52e06ff (2026-08-30). Data as JSON: /api/errors/f106691611aba153. Report an issue: GitHub.