docmirror/dev-sidecar · error

证书文件不存在: ${certPath}

Error message

证书文件不存在: ${certPath}

What it means

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.

Source

Thrown at packages/core/src/shell/scripts/setup-ca.js:12

const fs = require('node:fs')
const Shell = require('../shell')

const execute = Shell.execute

const executor = {
  async windows (exec, { certPath }) {
    if (!certPath) {
      throw new Error('证书路径为空,无法安装根证书。请确认证书文件已生成。')
    }
    if (!fs.existsSync(certPath)) {
      throw new Error(`证书文件不存在: ${certPath}`)
    }
    const cmds = [`start "" "${certPath}"`]
    await exec(cmds, { type: 'cmd' })
    return true
  },
  async linux (exec, { certPath }) {
    if (!certPath) {
      throw new Error('证书路径为空,无法安装根证书。请确认证书文件已生成。')
    }
    if (!fs.existsSync(certPath)) {
      throw new Error(`证书文件不存在: ${certPath}`)
    }
    const cmds = [`sudo cp ${certPath} /usr/local/share/ca-certificates`, 'sudo update-ca-certificates ']
    await exec(cmds)
    return true
  },
  async mac (exec, { certPath }) {
    if (!certPath) {

View on GitHub (pinned to 7710cd56cc)

Solutions

  1. Regenerate the certificate: restart dev-sidecar (or its cert module) so the root CA is recreated at the configured path
  2. Check that the file exists: ls/dir the configured certPath and fix the path in ~/.dev-sidecar/config.json if it is wrong
  3. Restore ~/.dev-sidecar permissions/writability so cert generation can write the file
  4. Reinstall/reset the app config to defaults to get the standard cert path

Example fix

// before
await shell.setupCa(exec, { certPath: 'C:/certs/old-ca.crt' }) // file deleted
// after
const certPath = path.join(os.homedir(), '.dev-sidecar', 'dev-sidecar.ca.crt')
if (!fs.existsSync(certPath)) await certApi.generateRootCert(certPath)
await shell.setupCa(exec, { certPath })
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs')
if (!fs.existsSync(certPath)) {
  await certApi.generateRootCert(certPath) // regenerate before installing
}

Type guard

function certFileExists(p) { return typeof p === 'string' && p.length > 0 && fs.existsSync(p) }

Try / catch

try {
  await shell.setupCa(exec, { certPath })
} catch (e) {
  if (String(e.message).includes('证书文件不存在')) {
    log.error(`CA file missing at ${certPath}; regenerating`)
    await certApi.generateRootCert(certPath)
    await shell.setupCa(exec, { certPath })
  } else { throw e }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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