decolua/9router · error · Error

Wrong sudo password | Failed to remove DNS entry: ${error.me

Error message

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

What it means

removeDNSEntry wraps all hosts-file mutation (sudo tee on Unix, elevated PowerShell on Windows) and DNS flush in try/catch. If the underlying exec fails with a message containing 'incorrect password' it rethrows 'Wrong sudo password'; any other failure is rethrown as 'Failed to remove DNS entry: <detail>'. This converts OS-level errors (bad sudo credential, hosts file permissions, missing ipconfig/flush) into a single clear error for callers.

Source

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

  try {
    if (IS_WIN) {
      const current = fs.readFileSync(HOSTS_FILE, "utf8");
      const filtered = current.split(/\r?\n/).filter(l => !entriesToRemove.some(h => l.includes(h))).join("\r\n");
      const next = filtered.replace(/[\r\n\s]+$/g, "") + "\r\n";
      atomicWriteHostsWin(HOSTS_FILE, current, next);
      await runElevatedPowerShell("ipconfig /flushdns | Out-Null");
    } else {
      const current = fs.readFileSync(HOSTS_FILE, "utf8");
      const filtered = current.split(/\r?\n/).filter(l => !entriesToRemove.some(h => l.includes(h))).join("\n");
      const next = filtered.replace(/[\r\n\s]+$/g, "") + "\n";
      const escaped = next.replace(/'/g, "'\\''");
      await execWithPassword(`printf '%s' '${escaped}' | tee ${HOSTS_FILE} > /dev/null`, sudoPassword);
      await flushDNS(sudoPassword);
    }
    log(`🌐 DNS ${tool}: ✅ removed ${entriesToRemove.join(", ")}`);
  } catch (error) {
    const msg = error.message?.includes("incorrect password") ? "Wrong sudo password" : `Failed to remove DNS entry: ${error.message}`;
    throw new Error(msg);
  }
}

/**
 * Remove ALL tool DNS entries (used when stopping server)
 */
async function removeAllDNSEntries(sudoPassword) {
  for (const tool of Object.keys(TOOL_HOSTS)) {
    try {
      await removeDNSEntry(tool, sudoPassword);
    } catch (e) {
      err(`DNS ${tool}: failed to remove — ${e.message}`);
    }
  }
}

/**
 * Sync removal of ALL tool DNS entries — for use during process shutdown

View on GitHub (pinned to 90b52e06ff)

Solutions

  1. Re-enter the correct sudo password and retry the call
  2. Clear any cached sudo password (e.g. setCachedPassword) so the user is re-prompted
  3. Verify manual sudo access: run `sudo -k; sudo -v` in a terminal to confirm the password works
  4. On Windows, run the process/dashboard as Administrator so the elevated PowerShell can write the hosts file
  5. Inspect the nested error.message after the pipe to identify non-password causes (permissions, missing flushdns)

Example fix

// before
await removeDNSEntry('cursor', stalePassword);
// after
try {
  await removeDNSEntry('cursor', passwordFromUserPrompt);
} catch (e) {
  if (e.message === 'Wrong sudo password') passwordFromUserPrompt = await promptForSudoPassword();
  else throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check sudo credential before mutating hosts (Unix)
const { execSync } = require('child_process');
try { execSync(`sudo -k -S -v`, { input: sudoPassword + '\n' }); }
catch { throw new Error('Provided sudo password is invalid'); }

Try / catch

try {
  await removeDNSEntry(tool, sudoPassword);
} catch (e) {
  if (e.message === 'Wrong sudo password') {
    sudoPassword = await promptForSudoPassword(); // re-prompt and retry once
    return removeDNSEntry(tool, sudoPassword);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling removeDNSEntry(tool, sudoPassword) where sudoPassword is wrong or stale (password changed, cached password expired); on Windows where the elevated PowerShell prompt was denied or UAC declined; hosts file locked/read-only or flushDNS command missing on the PATH.

Common situations: User typed the wrong sudo password into the dashboard prompt; macOS/Linux password rotated while the app cached an old one; running headless where sudo cannot prompt; Windows executed without admin rights so the hosts write fails.

Related errors


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