Skip to content

Commit 4306ac7

Browse files
committed
fix(table): revert default-case throw to plain Error and update JSDoc @throws tags
1 parent 049c6ca commit 4306ac7

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

apps/sim/lib/table/sql.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const ALLOWED_OPERATORS = new Set([
5252
* @param filter - Filter object with field conditions and logical operators
5353
* @param tableName - Table name for the query (e.g., 'user_table_rows')
5454
* @returns SQL WHERE clause or undefined if no filter specified
55-
* @throws Error if field name is invalid or operator is not allowed
55+
* @throws {TableQueryValidationError} if field name is invalid or operator is not allowed
5656
*
5757
* @example
5858
* // Simple equality
@@ -121,7 +121,7 @@ export function buildFilterClause(filter: Filter, tableName: string): SQL | unde
121121
* @param tableName - Table name for the query (e.g., 'user_table_rows')
122122
* @param columns - Optional column definitions for type-aware sorting
123123
* @returns SQL ORDER BY clause or undefined if no sort specified
124-
* @throws Error if field name is invalid
124+
* @throws {TableQueryValidationError} if field name or sort direction is invalid
125125
*
126126
* @example
127127
* buildSortClause({ name: 'asc', age: 'desc' }, 'user_table_rows')
@@ -161,7 +161,7 @@ export function buildSortClause(
161161
* Field names must match the NAME_PATTERN (alphanumeric + underscore, starting with letter/underscore).
162162
*
163163
* @param field - The field name to validate
164-
* @throws Error if field name is invalid
164+
* @throws {TableQueryValidationError} if field name is invalid
165165
*/
166166
function validateFieldName(field: string): void {
167167
if (!field || typeof field !== 'string') {
@@ -179,7 +179,7 @@ function validateFieldName(field: string): void {
179179
* Validates an operator to ensure it's in the allowed list.
180180
*
181181
* @param operator - The operator to validate
182-
* @throws Error if operator is not allowed
182+
* @throws {TableQueryValidationError} if operator is not allowed
183183
*/
184184
function validateOperator(operator: string): void {
185185
if (!ALLOWED_OPERATORS.has(operator)) {
@@ -203,7 +203,7 @@ function validateOperator(operator: string): void {
203203
* object with operators like $eq, $gt, $in, etc.
204204
* @returns Array of SQL condition fragments. Multiple conditions are returned
205205
* when the condition object contains multiple operators.
206-
* @throws Error if field name is invalid or operator is not allowed
206+
* @throws {TableQueryValidationError} if field name is invalid or operator is not allowed
207207
*/
208208
function buildFieldCondition(
209209
tableName: string,
@@ -273,8 +273,10 @@ function buildFieldCondition(
273273
break
274274

275275
default:
276-
// This should never happen due to validateOperator, but added for completeness
277-
throw new TableQueryValidationError(`Unsupported operator: ${op}`)
276+
// This should never happen due to validateOperator, but added for completeness.
277+
// Throw a plain Error (→ 500) since reaching this default means the switch
278+
// and ALLOWED_OPERATORS have drifted — that's a programmer error, not a caller error.
279+
throw new Error(`Unsupported operator: ${op}`)
278280
}
279281
}
280282
} else {

0 commit comments

Comments
 (0)