Skip to content

Commit a36114f

Browse files
waleedlatif1claude
andcommitted
fix(tinybird): fail loudly on invalid query_pipe parameters JSON
parsePipeParameters previously returned {} on any JSON parse error, so a mistyped 'parameters' input produced a successful pipe call with the dynamic filters silently dropped. Throw a clear error for non-empty, non-object input instead; an omitted/empty value still means 'no parameters'. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent ea0f8a2 commit a36114f

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

apps/sim/tools/tinybird/query_pipe.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,31 @@ const logger = createLogger('tinybird-query-pipe')
66

77
/**
88
* Parses the dynamic-parameters input, which may arrive as a JSON object or a
9-
* JSON string from a code/json subBlock. Returns an empty object on any failure.
9+
* JSON string from a code/json subBlock. An omitted or empty value means "no
10+
* parameters"; a non-empty value that is not a valid JSON object throws, so a
11+
* mistyped input fails loudly instead of silently dropping the filters.
1012
*/
1113
function parsePipeParameters(
1214
input: TinybirdQueryPipeParams['parameters']
1315
): Record<string, unknown> {
14-
if (!input) return {}
15-
if (typeof input === 'string') {
16-
const trimmed = input.trim()
17-
if (!trimmed) return {}
18-
try {
19-
const parsed = JSON.parse(trimmed)
20-
return parsed && typeof parsed === 'object' ? (parsed as Record<string, unknown>) : {}
21-
} catch {
22-
return {}
23-
}
16+
if (input === undefined || input === null) return {}
17+
if (typeof input === 'object') return input as Record<string, unknown>
18+
19+
const trimmed = input.trim()
20+
if (!trimmed) return {}
21+
22+
let parsed: unknown
23+
try {
24+
parsed = JSON.parse(trimmed)
25+
} catch {
26+
throw new Error(
27+
'Invalid Pipe parameters: expected a JSON object of key/value pairs (e.g. {"limit": 10})'
28+
)
29+
}
30+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
31+
throw new Error('Invalid Pipe parameters: expected a JSON object, not a primitive or array')
2432
}
25-
return typeof input === 'object' ? input : {}
33+
return parsed as Record<string, unknown>
2634
}
2735

2836
/**

0 commit comments

Comments
 (0)