{"record":{"id":"9f31a9075fe57b00","repo":"Mintplex-Labs/anything-llm","slug":"error-9f31a9","errorCode":null,"errorMessage":"${error}","messagePattern":"\\$\\{error\\}","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/telegram.js","lineNumber":140,"sourceCode":"        const existing = await ExternalCommunicationConnector.get(\"telegram\");\n        const storedConfig = {\n          bot_username: verification.username,\n          default_workspace: workspaceSlug,\n          approved_users: existing?.config?.approved_users || [],\n          voice_response_mode:\n            existing?.config?.voice_response_mode || \"text_only\",\n        };\n\n        // Save config with encrypted token\n        const { error } = await ExternalCommunicationConnector.upsert(\n          \"telegram\",\n          {\n            ...storedConfig,\n            bot_token: encryptToken(String(bot_token)),\n            active: true,\n          }\n        );\n        if (error) return response.status(500).json({ success: false, error });\n\n        // Start the bot with the plaintext token\n        const service = new TelegramBotService();\n        await service.start({ ...storedConfig, bot_token: String(bot_token) });\n\n        await EventLogs.logEvent(\"telegram_bot_connected\", {\n          bot_username: verification.username,\n        });\n        await Telemetry.sendTelemetry(\"telegram_bot_connected\");\n        return response.status(200).json({\n          success: true,\n          bot_username: verification.username,\n        });\n      } catch (e) {\n        console.error(e.message, e);\n        response.sendStatus(500);\n      }\n    }","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/telegram.js#L122-L158","documentation":"The 500 response on POST /telegram/connect when ExternalCommunicationConnector.upsert('telegram', {...}) returns an error. This is the persistence step that saves the connector row (with the encrypted token) to the system database, so the interpolated message is a database-layer failure string, not a Telegram error. The token itself was already verified at this point.","triggerScenarios":"SQLite write failure while upserting the external_communication_connectors row: database file locked by another process, read-only storage directory, disk full, or a serialization error on the stored config object. The connect flow dies after verification but before service.start().","commonSituations":"Two server instances or a stray process holding the DB lock; container with a read-only or full volume mounted at storage; migrations never applied so the connector table is missing; concurrent connect requests racing on the same row.","solutions":["Check the server console/log for the exact database error surfaced as error in the response body.","Ensure only one server process holds the database and that the storage directory is writable with free disk space.","Retry POST /telegram/connect once the underlying write succeeds - the token is re-verified each attempt, so no partial state remains."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch(\"/api/telegram/connect\", { method: \"POST\", headers, body: JSON.stringify({ bot_token }) });\n  if (res.status === 500) {\n    const { error } = await res.json(); // database-layer message, log it verbatim\n    console.error(\"connect persistence failed:\", error);\n  }\n} catch (e) {\n  // network-level failure of the API call itself\n  console.error(\"connect request failed:\", e.message);\n}","preventionTips":["Run exactly one server process against the database to avoid write locks.","Monitor disk space and storage-directory permissions where the SQLite file lives.","Treat the connect flow as transactional: a 500 here means no connector was saved, so a clean retry after fixing the DB is safe."],"tags":["telegram","database","persistence","sqlite"],"backgroundTag":"database-write-failed","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}