{"record":{"id":"db37fb5c24f0cde3","repo":"appwrite/appwrite","slug":"failed-to-issue-a-certificate-with-message-stder","errorCode":null,"errorMessage":"Failed to issue a certificate with message: {stderr}","messagePattern":"Failed to issue a certificate with message: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Appwrite/Certificates/LetsEncrypt.php","lineNumber":41,"sourceCode":"    {\n        $stdout = '';\n        $stderr = '';\n\n        $staging = (Http::isProduction()) ? '' : ' --dry-run';\n        $exit = Console::execute(\n            \"certbot certonly -v --webroot --noninteractive --agree-tos{$staging}\"\n            . \" --email \" . $this->email\n            . \" --cert-name \" . $certName\n            . \" -w \" . APP_STORAGE_CERTIFICATES\n            . \" -d {$domain}\",\n            '',\n            $stdout,\n            $stderr\n        );\n\n        // Unexpected error, usually 5XX, API limits, ...\n        if ($exit !== 0) {\n            throw new Exception('Failed to issue a certificate with message: ' . $stderr);\n        }\n\n        // Prepare folder in storage for domain\n        $path = APP_STORAGE_CERTIFICATES . '/' . $domain;\n        if (!\\is_readable($path)) {\n            if (!\\mkdir($path, 0755, true)) {\n                throw new Exception('Failed to create path for certificate.');\n            }\n        }\n\n        // Move generated files\n        if (!@\\rename('/etc/letsencrypt/live/' . $certName . '/cert.pem', APP_STORAGE_CERTIFICATES . '/' . $domain . '/cert.pem')) {\n            throw new Exception('Failed to rename certificate cert.pem. Let\\'s Encrypt log: ' . $stderr . ' ; ' . $stdout);\n        }\n\n        if (!@\\rename('/etc/letsencrypt/live/' . $certName . '/chain.pem', APP_STORAGE_CERTIFICATES . '/' . $domain . '/chain.pem')) {\n            throw new Exception('Failed to rename certificate chain.pem. Let\\'s Encrypt log: ' . $stderr . ' ; ' . $stdout);\n        }","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/appwrite/appwrite/blob/a1d520eea492ebd1da1ef2dc8db5b2b34e277dce/src/Appwrite/Certificates/LetsEncrypt.php#L23-L59","documentation":"DELETE /v1/functions/{functionId}/variables/{variableId} loads the parent function first; if getDocument('functions', $functionId) is empty it throws function_not_found (src/Appwrite/Platform/Modules/Functions/Http/Variables/Delete.php:81) before the variable is even looked up.","triggerScenarios":"Deleting a variable with a mistyped functionId; deleting against a function that was removed; using credentials bound to a different project.","commonSituations":"Cleanup scripts run after functions were re-created with new ids; environments drifted so the script's functionId list no longer matches the project.","solutions":["Resolve the function id via GET /v1/functions (list) before deleting its variables","Treat function_not_found on delete as already-done when writing idempotent cleanup","Verify the SDK/API-key project context matches the function's project"],"exampleFix":"// before\nawait functions.variables.delete('fnct_old_id', varId);\n\n// after\nconst fns = await functions.list();\nconst fn = fns.functions.find((f) => f.name === 'payments');\nif (fn) await functions.variables.delete(fn.$id, varId);","handlingStrategy":"validation","validationCode":"const fns = (await functions.list()).functions.map((f) => f.$id);\nif (!fns.includes(fnId)) {\n  console.warn(`function ${fnId} no longer exists; skipping variable cleanup`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await functions.variables.delete(fnId, varId);\n} catch (e) {\n  if (e instanceof AppwriteException && e.code === 'function_not_found') {\n    // parent already gone: nothing to clean, treat as success\n  } else throw e;\n}","preventionTips":["Make cleanup scripts idempotent: treat function_not_found/variable_not_found as done","Re-resolve function ids from a live list at the start of each run"],"tags":["appwrite","functions","variables","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"a1d520eea492ebd1da1ef2dc8db5b2b34e277dce","analyzedAt":"2026-08-18T21:34:56.994Z","contentChangedAt":"2026-08-18T21:34:56.994Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}