{"record":{"id":"26e0b3da875428b7","repo":"usebruno/bruno","slug":"error-reading-cert-key-file-err-message","errorCode":null,"errorMessage":"Error reading cert/key file: ${err.message}","messagePattern":"Error reading cert/key file: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-requests/src/utils/http-https-agents.ts","lineNumber":297,"sourceCode":"      if (requestUrl && requestUrl.match(hostRegex)) {\n        if (type === 'cert') {\n          try {\n            let certFilePath = clientCert?.certFilePath;\n            if (!certFilePath) {\n              throw new Error('certFilePath is required for cert type');\n            }\n            certFilePath = path.isAbsolute(certFilePath) ? certFilePath : path.join(collectionPath, certFilePath);\n            let keyFilePath = clientCert?.keyFilePath;\n            if (!keyFilePath) {\n              throw new Error('keyFilePath is required for cert type');\n            }\n            keyFilePath = path.isAbsolute(keyFilePath) ? keyFilePath : path.join(collectionPath, keyFilePath);\n\n            certsConfig.cert = fs.readFileSync(certFilePath);\n            certsConfig.key = fs.readFileSync(keyFilePath);\n          } catch (err: any) {\n            console.error('Error reading cert/key file', err);\n            throw new Error(`Error reading cert/key file: ${err.message}`);\n          }\n        } else if (type === 'pfx') {\n          try {\n            let pfxFilePath = clientCert?.pfxFilePath;\n            if (!pfxFilePath) {\n              throw new Error('pfxFilePath is required for pfx type');\n            }\n            pfxFilePath = path.isAbsolute(pfxFilePath) ? pfxFilePath : path.join(collectionPath, pfxFilePath);\n            certsConfig.pfx = fs.readFileSync(pfxFilePath);\n          } catch (err: any) {\n            console.error('Error reading pfx file', err);\n            throw new Error(`Error reading pfx file: ${err.message}`);\n          }\n        }\n        certsConfig.passphrase = clientCert.passphrase;\n        break;\n      }\n    }","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-requests/src/utils/http-https-agents.ts#L279-L315","documentation":"Catch-all around the cert/key loading block. Wraps any thrown error — including the required-field guards above and fs.readFileSync failures (ENOENT, EACCES, EISDIR) — with the 'Error reading cert/key file:' prefix.","triggerScenarios":"certFilePath/keyFilePath resolved to a missing/unreadable file, OR one of the required-field guards fired (in which case the suffix is itself 'certFilePath is required for cert type' etc.).","commonSituations":"Cert/key paths stored relative but resolved against an unexpected collectionPath; file moved or deleted; collection shared across machines with different absolute paths; the required-field message surfaces here because the try wraps the guards too.","solutions":["Read the suffix to separate missing-file (ENOENT) from missing-config ('... is required for cert type').","Confirm certFilePath and keyFilePath are absolute or correctly relative to collectionPath.","Re-pick both files in the Client Certificates UI after moving the collection."],"exampleFix":"// before: only cert was set, key path stale -> 'Error reading cert/key file: ENOENT'\n{ certFilePath:'/old/c.pem', keyFilePath:'/old/k.pem' }\n\n// after\n{ certFilePath:'/new/c.pem', keyFilePath:'/new/k.pem' }","handlingStrategy":"try-catch","validationCode":"import fs from 'node:fs';\nfor (const cc of certs) {\n  if (cc.disabled || cc.type === 'pfx') continue;\n  for (const p of [cc.certFilePath, cc.keyFilePath]) {\n    if (!p) continue;\n    const full = path.isAbsolute(p) ? p : path.join(collectionPath, p);\n    if (!fs.existsSync(full)) throw new Error(`cert/key file not found: ${full}`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try { configureCert(certsConfig, ...); } catch (e) { if (/Error reading cert\\/key file/.test(e.message)) { /* disable cert, retry without it */ } else throw e; }","preventionTips":["Inspect the suffix: required-field vs ENOENT.","Use absolute paths or paths relative to collectionPath."],"tags":["tls","client-cert","filesystem","wrapper"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}