docmirror/dev-sidecar · error

Unknown type DNS: ${server}, provider: ${provider}

Error message

Unknown type DNS: ${server}, provider: ${provider}

What it means

initDNS() parses each configured DNS provider to classify it as https/tls/tcp/udp. If a server string contains '://' but does not start with a recognized scheme (udp://, https://, tls://, dot://, tcp://), the library cannot infer the transport and throws immediately. This is a fail-fast guard against misconfigured DNS providers that would otherwise silently fail at query time.

Source

Thrown at packages/mitmproxy/src/lib/dns/index.js:37

      let server = conf.server || conf.host
      if (server != null) {
        server = server.replace(/\s+/, '')
      }
      if (!server) {
        continue
      }

      // 获取DNS类型
      let type = conf.type
      if (type == null) {
        if (server.startsWith('https://') || server.startsWith('http://')) {
          type = 'https'
        } else if (server.startsWith('tls://') || server.startsWith('dot://')) {
          type = 'tls'
        } else if (server.startsWith('tcp://')) {
          type = 'tcp'
        } else if (server.includes('://') && !server.startsWith('udp://')) {
          throw new Error(`Unknown type DNS: ${server}, provider: ${provider}`)
        } else {
          type = 'udp'
        }
      } else {
        type = type.replace(/\s+/, '').toLowerCase()
      }

      // 获取DNS的Family值
      const family = conf.family

      // 创建DNS对象
      if (type === 'https' || type === 'doh' || type === 'dns-over-https') {
        if (!server.includes('/')) {
          server = `https://${server}/dns-query`
        }

        // 基于 https
        dnsMap[provider] = new DNSOverHTTPS(provider, conf.cacheSize, preSetIpList, server, family, conf.sni || conf.servername)

View on GitHub (pinned to 7710cd56cc)

Solutions

  1. Open ~/.dev-sidecar/config.json (or the merged running config) and find the dns.providers entry referenced in the message
  2. Change the server scheme to a supported one: https://, tls:// (or dot://), tcp://, or udp:// (or a bare IP meaning udp)
  3. For DoH/DoT providers only available over QUIC, pick their https/tls endpoint instead (e.g. use https://cloudflare-dns.com/dns-query)
  4. If a custom type is intended, set the provider's explicit 'type' field to one of: https, tls, tcp, udp (whitespace is stripped and lowercased)

Example fix

// before
dns: { providers: { custom: { server: 'quic://dns.adguard.com' } } }
// after
dns: { providers: { custom: { server: 'https://dns.adguard.com/dns-query', type: 'https' } } }
Defensive patterns

Strategy: validation

Validate before calling

const SCHEMES = ['udp://', 'https://', 'tls://', 'dot://', 'tcp://']
function isValidDnsServer(p) {
  if (!p || !p.server) return false
  const s = String(p.server)
  if (p.type) return ['https', 'tls', 'tcp', 'udp'].includes(String(p.type).trim().toLowerCase())
  if (!s.includes('://')) return true
  return SCHEMES.some(pre => s.startsWith(pre))
}
// before startup: Object.entries(config.dns.providers).every(([k, p]) => isValidDnsServer(p))

Type guard

function hasKnownScheme(server) {
  return typeof server === 'string' && (
    !server.includes('://') ||
    /^(udp|https|tls|dot|tcp):\/\//.test(server)
  )
}

Try / catch

try {
  await DevSidecar.api.startup()
} catch (e) {
  if (String(e.message).startsWith('Unknown type DNS:')) {
    console.error('Bad dns provider config:', e.message)
    delete config.dns.providers.offending
    await DevSidecar.api.startup()
  } else throw e
}

Prevention

When it happens

Trigger: Calling initDNS/startup with config.dns.providers containing an entry whose server value has an unrecognized scheme, e.g. 'quic://dns.example.com', 'dns://1.1.1.1', or a typo like 'htps://dns.google'. Also thrown when a provider's 'type' field is absent and the server string cannot be classified.

Common situations: Users copy DNS provider entries from other tools (e.g. dnscrypt-proxy with 'sdns://' stamps or 'quic://' servers) into dev-sidecar config; typos in scheme names; hand-edited ~/.dev-sidecar/config.json overrides.

Related errors


AI-assisted analysis of docmirror/dev-sidecar@7710cd56cc (2026-08-31). Data as JSON: /api/errors/4a257f8b73100d1c. Report an issue: GitHub.