Skip to content

Commit b869f68

Browse files
KyleAMathewsclaudesamwillis
authored
fix: improve InvalidSourceError message clarity (#488)
Co-authored-by: Claude <[email protected]> Co-authored-by: Sam Willis <[email protected]>
1 parent 8665660 commit b869f68

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

.changeset/eleven-results-smoke.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@tanstack/db": patch
3+
---
4+
5+
fix: improve InvalidSourceError message clarity
6+
7+
The InvalidSourceError now provides a clear, actionable error message that:
8+
9+
- Explicitly states the problem is passing a non-Collection/non-subquery to a live query
10+
- Includes the alias name to help identify which source is problematic
11+
- Provides guidance on what should be passed instead (Collection instances or QueryBuilder subqueries)
12+
13+
This replaces the generic "Invalid source" message with helpful debugging information.

packages/db/src/errors.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,10 @@ export class SubQueryMustHaveFromClauseError extends QueryBuilderError {
302302
}
303303

304304
export class InvalidSourceError extends QueryBuilderError {
305-
constructor() {
306-
super(`Invalid source`)
305+
constructor(alias: string) {
306+
super(
307+
`Invalid source for live query: The value provided for alias "${alias}" is not a Collection or subquery. Live queries only accept Collection instances or subqueries. Please ensure you're passing a valid Collection or QueryBuilder, not a plain array or other data type.`
308+
)
307309
}
308310
}
309311

packages/db/src/query/builder/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class BaseQueryBuilder<TContext extends Context = Context> {
7070
}
7171
ref = new QueryRef(subQuery, alias)
7272
} else {
73-
throw new InvalidSourceError()
73+
throw new InvalidSourceError(alias)
7474
}
7575

7676
return [alias, ref]

0 commit comments

Comments
 (0)