{"record":{"id":"baa8c7dd2ae39e48","repo":"mihomo-party-org/clash-party","slug":"get-service-failed","errorCode":null,"errorMessage":"Get service failed","messagePattern":"Get service failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/main/core/dns.ts","lineNumber":36,"sourceCode":"export async function getDefaultDevice(): Promise<string> {\n  const { stdout: deviceOut } = await execPromise(`route -n get default`)\n  let device = deviceOut.split('\\n').find((s) => s.includes('interface:'))\n  device = device?.trim().split(' ').slice(1).join(' ')\n  if (!device) throw new Error('Get device failed')\n  return device\n}\n\nasync function getDefaultService(): Promise<string> {\n  const device = await getDefaultDevice()\n  const { stdout: order } = await execPromise(`networksetup -listnetworkserviceorder`)\n  const block = order.split('\\n\\n').find((s) => s.includes(`Device: ${device}`))\n  if (!block) throw new Error('Get networkservice failed')\n  for (const line of block.split('\\n')) {\n    if (line.match(/^\\(\\d+\\).*/)) {\n      return line.trim().split(' ').slice(1).join(' ')\n    }\n  }\n  throw new Error('Get service failed')\n}\n\nasync function getOriginDNS(): Promise<void> {\n  const service = await getDefaultService()\n  const { stdout: dns } = await execPromise(`networksetup -getdnsservers \"${service}\"`)\n  if (dns.startsWith(\"There aren't any DNS Servers set on\")) {\n    await patchAppConfig({ originDNS: 'Empty' })\n  } else {\n    await patchAppConfig({ originDNS: dns.trim().replace(/\\n/g, ' ') })\n  }\n}\n\nasync function setDNS(dns: string, timeout?: number): Promise<void> {\n  const service = await getDefaultService()\n  try {\n    await axios.post(\n      'http://localhost/dns',\n      { service, dns },","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/mihomo-party-org/clash-party/blob/911e090537acdf7c50bee1c3aebecc2ef119a8b5/src/main/core/dns.ts#L18-L54","documentation":"Within getDefaultService, after finding the matching block for the device, the function scans its lines for one matching /^\\(\\d+\\).*/ (the numbered service line). If the block exists but no numbered service line parses, it throws 'Get service failed' — an unexpected networksetup output format.","triggerScenarios":"service() → getDefaultService() where the `Device: <device>` block was found but none of its lines start with '(N)', e.g. localized/changed networksetup output format or malformed block.","commonSituations":"Non-English macOS locale or future macOS changing networksetup formatting; corrupted NetworkExtensions preferences producing a block without the numbered service header; output parsing assumptions broken by whitespace changes.","solutions":["Inspect `networksetup -listnetworkserviceorder` output and compare its format with the expected '(1) ServiceName' pattern.","Update the app if macOS changed the output format.","Repair network services (remove/re-add the service in System Settings) to restore normal output.","As a workaround set DNS manually via System Settings instead of this API."],"exampleFix":"// expected block format\n// (1) Wi-Fi\n// (Hardware Port: Wi-Fi, Device: en0)\n// if block lacks '(N) ' lines -> throws; re-add the service to restore format","handlingStrategy":"try-catch","validationCode":"const { stdout: order } = await execPromise('networksetup -listnetworkserviceorder')\nconst block = order.split('\\n\\n').find((s) => s.includes(`Device: ${device}`))\nconst hasNumberedLine = !!block && block.split('\\n').some((l) => /^\\(\\d+\\).*/.test(l))\nif (!hasNumberedLine) {\n  // unexpected networksetup format — do not proceed\n}","typeGuard":null,"tryCatchPattern":"try {\n  const service = await getDefaultService()\n} catch (e) {\n  if (e.message === 'Get service failed') {\n    // networksetup output format changed or is corrupted; set DNS manually\n  }\n}","preventionTips":["Test against the macOS versions/locales you support.","Repair malformed network services in System Settings if output looks wrong.","Avoid relying on exact networksetup formatting without a fallback."],"tags":["macos","networksetup","dns","parsing"],"backgroundTag":"unexpected-command-output-format","analyzedSha":"911e090537acdf7c50bee1c3aebecc2ef119a8b5","analyzedAt":"2026-08-30T13:00:49.174Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}