docmirror/dev-sidecar · warning

macOS 代理服务检测:获取所有网络服务列表失败:

Error message

macOS 代理服务检测:获取所有网络服务列表失败:

What it means

Non-fatal warning from getMacNetworkService(). The last-resort command `networksetup -listallnetworkservices` itself threw, so no fallback service could be selected. Immediately after this warning the function throws the fatal Error '未找到可用的 macOS 网络服务,无法设置系统代理', which propagates to executor.mac() and fails the set-system-proxy operation.

Source

Thrown at packages/core/src/shell/scripts/set-system-proxy/index.js:274

        log.warn('macOS 代理服务检测:获取网络服务列表失败:', e.message, ',尝试备用方法')
      }
    } else {
      log.warn('macOS 代理服务检测:未检测到当前网络设备,尝试备用方法')
    }
  } catch (e) {
    log.warn('macOS 代理服务检测:获取路由信息失败:', e.message, ',尝试备用方法')
  }

  try {
    const allServicesOutput = await exec('networksetup -listallnetworkservices')
    const fallbackService = pickMacNetworkService(allServicesOutput)
    if (fallbackService) {
      log.info('macOS 代理服务检测:通过服务列表备用方法找到网络服务:', fallbackService)
      return fallbackService
    }
    log.warn('macOS 代理服务检测:未通过服务列表找到可用网络服务')
  } catch (e) {
    log.warn('macOS 代理服务检测:获取所有网络服务列表失败:', e.message)
  }

  throw new Error('未找到可用的 macOS 网络服务,无法设置系统代理')
}

// macOS exit code 14 = "You don't have permission to change the system preferences."
const MACOS_NETWORKSETUP_PERMISSION_ERROR_CODE = 14

/**
 * POSIX single-quote escaping: wraps `arg` in single quotes, escaping any
 * embedded single quotes with the '\''-idiom.  This prevents shell
 * metacharacter expansion regardless of the character set of the value.
 * @param {string|number} arg
 * @returns {string}
 */
function shellEscapeArg (arg) {
  return "'" + String(arg).replace(/'/g, "'\\''") + "'"
}

View on GitHub (pinned to 7710cd56cc)

Solutions

  1. Fix the root cause shown in the logged e.message, then retry enabling the proxy in DevSidecar
  2. Run `networksetup -listallnetworkservices` manually in Terminal to confirm it works for your user; if it errors there, repair macOS network settings (delete and recreate services, or consult IT for managed restrictions)
  3. Set the system proxy manually via System Settings and disable automatic proxy configuration (proxy.enable=false) in DevSidecar config
Defensive patterns

Strategy: try-catch

Validate before calling

const { execSync } = require('node:child_process')
function canListServices() {
  try { execSync('networksetup -listallnetworkservices', { stdio: 'ignore' }); return true }
  catch (e) { console.warn('networksetup unusable:', e.message); return false }
}

Try / catch

try {
  await DevSidecar.api.startup()
} catch (e) {
  if (e.message.includes('未找到可用的 macOS 网络服务')) {
    console.error('Automatic macOS proxy setup impossible; set proxy in System Settings manually')
  }
}

Prevention

When it happens

Trigger: networksetup cannot be spawned (missing from PATH, exec failure) or exits non-zero when listing services — e.g. sandbox restrictions, damaged network preferences, or the process lacking a proper user session/audit context.

Common situations: App launched from a stripped environment (launchd job, IDE debugger with minimal PATH); enterprise-managed Macs where networksetup is restricted; corrupted /Library/Preferences/SystemConfiguration contents.

Related errors


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