{"record":{"id":"ea5557f44445c518","repo":"ToolJet/ToolJet","slug":"error","errorCode":null,"errorMessage":"Error","messagePattern":"Error","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"plugins/packages/couchdb/lib/index.ts","lineNumber":129,"sourceCode":"    }\n\n    return {\n      status: 'ok',\n      data: result,\n    };\n  }\n\n  async testConnection(sourceOptions: SourceOptions): Promise<ConnectionTestResult> {\n    // eslint-disable-next-line @typescript-eslint/no-unused-vars\n    const { username, password, port, host, database, protocol } = sourceOptions;\n    const combined = `${username}:${password}`;\n    const key = Buffer.from(combined).toString('base64');\n    const client = await got(`${protocol}://${host}:${port}/_all_dbs`, {\n      method: 'get',\n      headers: { Authorization: `Basic ${key}` },\n    });\n    if (!client) {\n      throw new Error('Error');\n    }\n\n    return {\n      status: 'ok',\n    };\n  }\n\n  private parseJSON(json?: string): object {\n    if (!json) return {};\n\n    return JSON5.parse(json);\n  }\n}\n","sourceCodeStart":111,"sourceCodeEnd":143,"githubUrl":"https://github.com/ToolJet/ToolJet/blob/20602a8e101f2e59686c9afde0d1402aac2c8871/plugins/packages/couchdb/lib/index.ts#L111-L143","documentation":"In testConnection the plugin calls got(...) and then checks `if (!client) throw new Error('Error')`. Because got resolves with a Response object on success and rejects (throws) on any HTTP/network failure, a falsy return is effectively unreachable — the guard is dead defensive code, and its message ('Error') conveys no diagnostic information.","triggerScenarios":"Theoretically fires only if got returned a falsy value, which it does not in normal operation. In practice every real failure (bad credentials, unreachable host) surfaces as a got rejection that escapes this function before the check runs.","commonSituations":"A developer sees 'Error' with no context during connection testing; the actual cause is a got HTTPError (401/404) or a connection error that was thrown, not a falsy client.","solutions":["Look at the real thrown error from got (status code / ECONNREFUSED) — the 'Error' message is not the root cause.","Verify protocol, host, port, username, and password in sourceOptions.","Confirm the CouchDB instance is reachable from the ToolJet server.","If maintaining this plugin, replace the generic check with a proper status-code assertion that includes detail.","Remove the dead guard since got never returns falsy."],"exampleFix":"// before\nconst client = await got(url, { method: 'get', headers });\nif (!client) {\n  throw new Error('Error');\n}\n// after - assert on a meaningful status, or rely on got throwing on non-2xx\nconst res = await got(url, { method: 'get', headers, throwHttpErrors: true });\nif (res.statusCode !== 200) {\n  throw new Error(`CouchDB connection test failed: HTTP ${res.statusCode}`);\n}","handlingStrategy":"try-catch","validationCode":"async function probeCouch(sourceOptions: any) {\n  const { protocol, host, port, username, password } = sourceOptions;\n  const key = Buffer.from(`${username}:${password}`).toString('base64');\n  try {\n    const res = await got(`${protocol}://${host}:${port}/_all_dbs`, { headers: { Authorization: `Basic ${key}` } });\n    if (!Array.isArray(JSON.parse(res.body))) throw new Error('CouchDB did not return a database list');\n  } catch (err) {\n    throw new Error(`CouchDB unreachable: ${err.message}`);\n  }\n}","typeGuard":"function isGotHttpError(err: any): boolean {\n  return err?.name === 'HTTPError';\n}","tryCatchPattern":"try {\n  await couchdb.testConnection(sourceOptions);\n} catch (err) {\n  // The 'Error' message is dead code; the real cause is a got HTTPError/connection error.\n  const status = err?.response?.statusCode;\n  if (status === 401) throw new Error('CouchDB credentials are invalid');\n  if (status === 404) throw new Error('CouchDB endpoint not found');\n  if (err?.code === 'ECONNREFUSED') throw new Error('CouchDB host/port unreachable');\n  throw err;\n}","preventionTips":["Do not trust the generic 'Error' message — inspect the underlying got error/status.","Confirm protocol/host/port form a reachable URL from the ToolJet host.","Verify credentials with a direct curl before configuring the datasource.","If maintaining the plugin, remove the dead `if (!client)` guard.","Open the CouchDB port in firewalls between ToolJet and CouchDB."],"tags":["couchdb","dead-code","error-handling","http"],"backgroundTag":null,"analyzedSha":"20602a8e101f2e59686c9afde0d1402aac2c8871","analyzedAt":"2026-08-13T05:58:54.221Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}