{"record":{"id":"9c74bb385285b98c","repo":"docmirror/dev-sidecar","slug":"macos-9c74bb","errorCode":null,"errorMessage":"macOS 代理服务检测：未通过服务列表找到可用网络服务","messagePattern":"macOS 代理服务检测：未通过服务列表找到可用网络服务","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/core/src/shell/scripts/set-system-proxy/index.js","lineNumber":272,"sourceCode":"        log.warn('macOS 代理服务检测：未通过设备名匹配到网络服务，尝试备用方法')\n      } catch (e) {\n        log.warn('macOS 代理服务检测：获取网络服务列表失败:', e.message, '，尝试备用方法')\n      }\n    } else {\n      log.warn('macOS 代理服务检测：未检测到当前网络设备，尝试备用方法')\n    }\n  } catch (e) {\n    log.warn('macOS 代理服务检测：获取路由信息失败:', e.message, '，尝试备用方法')\n  }\n\n  try {\n    const allServicesOutput = await exec('networksetup -listallnetworkservices')\n    const fallbackService = pickMacNetworkService(allServicesOutput)\n    if (fallbackService) {\n      log.info('macOS 代理服务检测：通过服务列表备用方法找到网络服务:', fallbackService)\n      return fallbackService\n    }\n    log.warn('macOS 代理服务检测：未通过服务列表找到可用网络服务')\n  } catch (e) {\n    log.warn('macOS 代理服务检测：获取所有网络服务列表失败:', e.message)\n  }\n\n  throw new Error('未找到可用的 macOS 网络服务，无法设置系统代理')\n}\n\n// macOS exit code 14 = \"You don't have permission to change the system preferences.\"\nconst MACOS_NETWORKSETUP_PERMISSION_ERROR_CODE = 14\n\n/**\n * POSIX single-quote escaping: wraps `arg` in single quotes, escaping any\n * embedded single quotes with the '\\''-idiom.  This prevents shell\n * metacharacter expansion regardless of the character set of the value.\n * @param {string|number} arg\n * @returns {string}\n */\nfunction shellEscapeArg (arg) {","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/docmirror/dev-sidecar/blob/7710cd56cce760c708f30b01d2d4056eb8c402d5/packages/core/src/shell/scripts/set-system-proxy/index.js#L254-L290","documentation":"Non-fatal warning from the fallback stage of getMacNetworkService(). Both primary strategies failed, so the code listed all services via `networksetup -listallnetworkservices` and ran pickMacNetworkService(), which returned null (empty or unusable list). This warning is logged just before the function throws the fatal Error '未找到可用的 macOS 网络服务，无法设置系统代理'.","triggerScenarios":"`networksetup -listallnetworkservices` returns output containing only the asterisk legend line ('An asterisk (*) denotes...') and no service names, or an empty string — i.e. the system reports no network services at all.","commonSituations":"Macs with all network services deleted in System Settings > Network; corrupted network configuration; headless/virtualized macOS images with no configured interfaces.","solutions":["Recreate a network service in System Settings > Network (add Wi-Fi or Ethernet service) so networksetup can report at least one service","Verify with `networksetup -listallnetworkservices` that at least one real service name is printed; if not, repair network configuration or reset NVRAM/network settings","If automatic proxy setup cannot work, set the macOS proxy manually (System Settings > Network > Proxies) or skip the proxy.enable option in DevSidecar config"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const { execSync } = require('node:child_process')\nfunction hasNetworkServices() {\n  try {\n    const out = execSync('networksetup -listallnetworkservices').toString()\n    const services = out.split(/\\r?\\n/).map(s => s.replace(/^\\*/, '').trim())\n      .filter(s => s && !s.startsWith('An asterisk'))\n    return services.length > 0\n  } catch { return false }\n}\nif (!hasNetworkServices()) throw new Error('No macOS network services configured; create one in System Settings')","typeGuard":"function extractServices(output) {\n  if (typeof output !== 'string') return []\n  return output.split(/\\r?\\n/).map(s => s.replace(/^\\*/, '').trim())\n    .filter(s => s && !s.startsWith('An asterisk (*) denotes'))\n}","tryCatchPattern":"try {\n  await DevSidecar.api.config.set('proxy.enable', true)\n} catch (e) {\n  if (e.message.includes('未找到可用的 macOS 网络服务')) {\n    // guide user to recreate a network service or set proxy manually\n  }\n}","preventionTips":["Never delete all services in System Settings > Network","On VM/headless macOS images, provision at least one network service","Verify `networksetup -listallnetworkservices` lists a real service before enabling automation"],"tags":["macos","networksetup","no-network-service","fatal-followup"],"backgroundTag":"macos-network-service-not-found","analyzedSha":"7710cd56cce760c708f30b01d2d4056eb8c402d5","analyzedAt":"2026-08-31T22:07:07.234Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}