PAC-E016 · unreachable-code

Statements after an unconditional return

medium · Errors and robustness

Statements that follow a return in the same block are never executed. Rules placed there look active but have no effect.

Why it matters

In PAC files this usually happens when a return "PROXY ..." default is placed in the middle of the function and further if blocks are appended after it. Those later rules never run. The PAC passes every test that happens to hit the earlier branches, and the operator wonders why the new exception “does not work”.

How to fix

Move the unconditional return to the end of the function; delete code that is really obsolete.

Examples

Bad

function FindProxyForURL(url, host) {
  if (isPlainHostName(host)) {
    return "DIRECT";
  }
  return "PROXY proxy.corp.example:8080";
  if (dnsDomainIs(host, ".corp.example")) {
    return "DIRECT";
  }
}
Open bad example in checker

Good

function FindProxyForURL(url, host) {
  if (isPlainHostName(host) || dnsDomainIs(host, ".corp.example")) {
    return "DIRECT";
  }
  return "PROXY proxy.corp.example:8080";
}
Open good example in checker

Related rules

References