{"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":47,"sourceCode":"            ->argument('certonly')\n            ->flag('-v')\n            ->flag('--webroot')\n            ->flag('--noninteractive')\n            ->flag('--agree-tos')\n            ->option('--email', $this->email)\n            ->option('--cert-name', $certName)\n            ->option('-w', APP_STORAGE_CERTIFICATES)\n            ->option('-d', $domain);\n\n        if (!Http::isProduction()) {\n            $certbot->flag('--dry-run');\n        }\n\n        $exit = Console::execute($certbot, '', $stdout, $stderr);\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":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/appwrite/appwrite/blob/ca3c55abfe2c8014937fdf778716af4524f2fcfc/src/Appwrite/Certificates/LetsEncrypt.php#L29-L65","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":"ca3c55abfe2c8014937fdf778716af4524f2fcfc","analyzedAt":"2026-08-18T21:34:56.994Z","contentChangedAt":"2026-08-18T21:34:56.994Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}