louislam/uptime-kuma · error · Error

Query returned no results

Error message

Query returned no results

What it means

Thrown by MssqlMonitorType.mssqlQuerySingleValue when the query's recordset is empty (or absent). This path runs only when conditions are enabled, because the monitor expects a single scalar to feed the condition evaluator. An empty result means there is no value to compare, so the check fails before conditions are evaluated.

Source

Thrown at server/monitor-types/mssql.js:104

        }
    }

    /**
     * Run a query on MSSQL server expecting a single value result
     * @param {string} connectionString The database connection string
     * @param {string} query The query to validate the database with
     * @returns {Promise<any>} Single value from the first column of the first row
     */
    async mssqlQuerySingleValue(connectionString, query) {
        let pool;
        try {
            pool = new mssql.ConnectionPool(connectionString);
            await pool.connect();
            const result = await pool.request().query(query);

            // Check if we have results
            if (!result.recordset || result.recordset.length === 0) {
                throw new Error("Query returned no results");
            }

            // Check if we have multiple rows
            if (result.recordset.length > 1) {
                throw new Error("Multiple values were found, expected only one value");
            }

            const firstRow = result.recordset[0];
            const columnNames = Object.keys(firstRow);

            // Check if we have multiple columns
            if (columnNames.length > 1) {
                throw new Error("Multiple columns were found, expected only one value");
            }

            // Return the single value from the first (and only) column
            return firstRow[columnNames[0]];
        } catch (err) {

View on GitHub (pinned to 6b5ea01557)

Solutions

  1. Run the query in SSMS against the monitored database and confirm it returns exactly one row with one column.
  2. If empty results are legitimate, restructure the query to always return a scalar (e.g. SELECT COUNT(*) or ISNULL((SELECT ...),0)).
  3. Loosen or correct the WHERE clause so the expected row exists.
  4. Turn conditions off if you only need connection/row-count semantics.

Example fix

-- before: SELECT balance FROM accounts WHERE id=@id   (id missing -> 0 rows)
-- after:  SELECT ISNULL((SELECT balance FROM accounts WHERE id=@id), -1);
Defensive patterns

Strategy: validation

Validate before calling

async function assertSingleValueQuery(connStr, query) {
  const pool = new mssql.ConnectionPool(connStr); await pool.connect();
  const r = await pool.request().query(query); await pool.close();
  if (!r.recordset || r.recordset.length === 0) throw new Error('query returns 0 rows');
  if (r.recordset.length > 1) throw new Error('query returns >1 row');
  if (Object.keys(r.recordset[0]).length > 1) throw new Error('query returns >1 column');
  return r.recordset[0][Object.keys(r.recordset[0])[0]];
}

Type guard

function isSingleValueRecordset(r) { return r?.recordset?.length === 1 && Object.keys(r.recordset[0]).length === 1; }

Prevention

When it happens

Trigger: monitor.conditions is non-empty, mssqlQuerySingleValue runs the query, result.recordset is falsy or result.recordset.length === 0. Typical when a WHERE clause filters every row, an aggregate finds no rows (e.g. MAX over empty set becomes NULL row only without GROUP BY in some setups), or the wrong database/table is queried.

Common situations: WHERE clause too restrictive (date filter, tenant id); table renamed/migrated so query finds nothing; query written for the legacy row-count path but conditions turned on; environment-specific data missing in the monitored DB.

Related errors


AI-assisted analysis of louislam/uptime-kuma@6b5ea01557 (2026-08-12). Data as JSON: /api/errors/a4fe1acd80752690. Report an issue: GitHub.