Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix: prevent marking formulas as invalid due to transient connection errors

Pranav C9ff7585fcb26
diff --git a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts
index 910fde1f1b..3d8a018b79 100644
--- a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts
+++ b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts
@@ -10,6 +10,7 @@ import {
} from 'nocodb-sdk';
import { getColumnName } from 'src/helpers/dbHelpers';
import { DBErrorExtractor } from 'src/helpers/db-error/extractor';
+import { isTransientError } from 'src/helpers/db-error/utils';
import genRollupSelectv2 from '../genRollupSelectv2';
import { replaceDelimitedWithKeyValuePg } from '../aggregations/pg';
import { replaceDelimitedWithKeyValueSqlite3 } from '../aggregations/sqlite3';
@@ -554,13 +555,18 @@ export default async function formulaQueryBuilderv2({
context.cacheMap?.clear();
}
} catch (e) {
+ // Check if this is a transient error (connection/timeout issue)
+ const isTransient = isTransientError(e);
+
// Mark formula error if formula validation is invoked
// or if a circular reference error occurs and a column is provided
+ // BUT skip marking for transient errors
if (
- validateFormula ||
- (column?.id &&
- e instanceof NcBaseErrorv2 &&
- e.error === NcErrorType.ERR_CIRCULAR_REF_IN_FORMULA)
+ !isTransient &&
+ (validateFormula ||
+ (column?.id &&
+ e instanceof NcBaseErrorv2 &&
+ e.error === NcErrorType.ERR_CIRCULAR_REF_IN_FORMULA))
) {
console.error(e);
@@ -577,9 +583,7 @@ export default async function formulaQueryBuilderv2({
error: e.message,
},
);
- } else if (
- ![NcErrorType.ERR_EXTERNAL_DATA_SOURCE_TIMEOUT].includes(e.error)
- ) {
+ } else {
// add formula error to show in UI
await FormulaColumn.update(context, column.id, {
error: e.message,
diff --git a/packages/nocodb/src/helpers/db-error/utils.ts b/packages/nocodb/src/helpers/db-error/utils.ts
index a3ba059d38..5188940ce8 100644
--- a/packages/nocodb/src/helpers/db-error/utils.ts
+++ b/packages/nocodb/src/helpers/db-error/utils.ts
@@ -1,3 +1,5 @@
+import { NcBaseErrorv2, NcErrorType } from 'nocodb-sdk';
+
export type DBErrorExtractResult =
| {
message: string;
@@ -22,3 +24,83 @@ export enum DBError {
DATA_TYPE_MISMATCH = 'DATA_TYPE_MISMATCH',
UNIQUE_CONSTRAINT_VIOLATION = 'UNIQUE_CONSTRAINT_VIOLATION',
}
+
+/**
+ * Determines if an error is transient (connection/infrastructure issue)
+ * rather than a permanent validation/logic error.
+ *
+ * Transient errors include:
+ * - Connection failures (ECONNREFUSED, ETIMEDOUT, etc.)
+ * - Database timeouts
+ * - Network issues
+ * - Temporary DNS failures
+ *
+ * These errors should NOT mark formulas/queries as permanently invalid.
+ */
+export function isTransientError(error: any): boolean {
+ // Check for NcBaseErrorv2 with specific transient error types
+ if (error instanceof NcBaseErrorv2) {
+ const transientErrorTypes = [
+ NcErrorType.ERR_EXTERNAL_DATA_SOURCE_TIMEOUT,
+ NcErrorType.ERR_DATABASE_OP_FAILED,
+ ];
+ if (transientErrorTypes.includes(error.error)) {
+ return true;
+ }
+ }
+
+ // Check for common connection error codes
+ const connectionErrorCodes = [
+ 'ECONNREFUSED', // Connection refused
+ 'ETIMEDOUT', // Connection timeout
+ 'ENOTFOUND', // DNS lookup failed
+ 'ECONNRESET', // Connection reset
+ 'EHOSTUNREACH', // Host unreachable
+ 'EAI_AGAIN', // DNS temporary failure
+ 'EPIPE', // Broken pipe
+ 'ENETUNREACH', // Network unreachable
+ ];
+
+ if (error?.code && connectionErrorCodes.includes(error.code)) {
+ return true;
+ }
+
+ // Check for database-specific timeout/connection errors
+ if (error?.code) {
+ const code = String(error.code);
+ // PostgreSQL connection errors (Class 08 - Connection Exception)
+ if (code.startsWith('08')) return true;
+ // PostgreSQL timeout errors
+ if (['40P01', '57014', '57P01'].includes(code)) return true;
+ // PostgreSQL too many connections
+ if (code === '53300') return true;
+ // MySQL connection/timeout errors
+ if (
+ [
+ 'ER_LOCK_WAIT_TIMEOUT',
+ 'ER_CON_COUNT_ERROR',
+ 'ER_TOO_MANY_USER_CONNECTIONS',
+ ].includes(code)
+ ) {
+ return true;
+ }
+ }
+
+ // Check error message for connection-related keywords
+ const errorMessage = error?.message?.toLowerCase() || '';
+ const connectionKeywords = [
+ 'connection',
+ 'timeout',
+ 'timed out',
+ 'unreachable',
+ 'network',
+ 'econnrefused',
+ 'etimedout',
+ ];
+
+ if (connectionKeywords.some((keyword) => errorMessage.includes(keyword))) {
+ return true;
+ }
+
+ return false;
+}