{"record":{"id":"acb416b1048f76d5","repo":"docmirror/dev-sidecar","slug":"certpath","errorCode":null,"errorMessage":"证书文件不存在: ${certPath}","messagePattern":"证书文件不存在: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/shell/scripts/setup-ca.js","lineNumber":12,"sourceCode":"const fs = require('node:fs')\nconst Shell = require('../shell')\n\nconst execute = Shell.execute\n\nconst executor = {\n  async windows (exec, { certPath }) {\n    if (!certPath) {\n      throw new Error('证书路径为空，无法安装根证书。请确认证书文件已生成。')\n    }\n    if (!fs.existsSync(certPath)) {\n      throw new Error(`证书文件不存在: ${certPath}`)\n    }\n    const cmds = [`start \"\" \"${certPath}\"`]\n    await exec(cmds, { type: 'cmd' })\n    return true\n  },\n  async linux (exec, { certPath }) {\n    if (!certPath) {\n      throw new Error('证书路径为空，无法安装根证书。请确认证书文件已生成。')\n    }\n    if (!fs.existsSync(certPath)) {\n      throw new Error(`证书文件不存在: ${certPath}`)\n    }\n    const cmds = [`sudo cp ${certPath} /usr/local/share/ca-certificates`, 'sudo update-ca-certificates ']\n    await exec(cmds)\n    return true\n  },\n  async mac (exec, { certPath }) {\n    if (!certPath) {","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/docmirror/dev-sidecar/blob/7710cd56cce760c708f30b01d2d4056eb8c402d5/packages/core/src/shell/scripts/setup-ca.js#L1-L30","documentation":"On Windows, after confirming certPath is non-empty, the setup-ca executor checks that the certificate file actually exists on disk via fs.existsSync(). If the CA cert file has not been generated (or was deleted), it throws this error naming the missing path instead of running `start <certPath>` to install it.","triggerScenarios":"Calling setupCa(exec, { certPath }) on Windows where the path is set but the file does not exist — e.g. cert generation was never run, the file was manually deleted from ~/.dev-sidecar, or a wrong/custom path was supplied in config.","commonSituations":"User cleaned ~/.dev-sidecar (or ran a disk cleanup) removing dev-sidecar.ca.crt while config still references it; app moved to a different user account so the old absolute path is gone; config `cert.path` typo pointing to a nonexistent file.","solutions":["Regenerate the certificate: restart dev-sidecar (or its cert module) so the root CA is recreated at the configured path","Check that the file exists: ls/dir the configured certPath and fix the path in ~/.dev-sidecar/config.json if it is wrong","Restore ~/.dev-sidecar permissions/writability so cert generation can write the file","Reinstall/reset the app config to defaults to get the standard cert path"],"exampleFix":"// before\nawait shell.setupCa(exec, { certPath: 'C:/certs/old-ca.crt' }) // file deleted\n// after\nconst certPath = path.join(os.homedir(), '.dev-sidecar', 'dev-sidecar.ca.crt')\nif (!fs.existsSync(certPath)) await certApi.generateRootCert(certPath)\nawait shell.setupCa(exec, { certPath })","handlingStrategy":"validation","validationCode":"const fs = require('fs')\nif (!fs.existsSync(certPath)) {\n  await certApi.generateRootCert(certPath) // regenerate before installing\n}","typeGuard":"function certFileExists(p) { return typeof p === 'string' && p.length > 0 && fs.existsSync(p) }","tryCatchPattern":"try {\n  await shell.setupCa(exec, { certPath })\n} catch (e) {\n  if (String(e.message).includes('证书文件不存在')) {\n    log.error(`CA file missing at ${certPath}; regenerating`)\n    await certApi.generateRootCert(certPath)\n    await shell.setupCa(exec, { certPath })\n  } else { throw e }\n}","preventionTips":["Regenerate the CA after cleaning ~/.dev-sidecar","Keep the cert path stable and under the current user's home directory","Check file existence before install calls","Do not hardcode absolute cert paths that break across machines"],"tags":["certificate","windows","file-not-found"],"backgroundTag":"ca-cert-file-not-found","analyzedSha":"7710cd56cce760c708f30b01d2d4056eb8c402d5","analyzedAt":"2026-08-31T22:07:07.234Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}