Skip to content

Commit 57027e6

Browse files
thomasballingerdjbalin
authored andcommitted
convex-backend PR 108: print tablename in unique() error message (#38187)
Improves usefulness of the error thrown when `.unique()` returns more than 1 result by now also printing the table name. Improves quality of life: currently, it can be cumbersome to identify the actual table in which these non-unique elements belong. This solution is a bit work-around-y, but it's the only solution I could come up with. Let me know if there is a better way to achieve this! ---- By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. Co-authored-by: Jan-Georges Jersild Balin <[email protected]> GitOrigin-RevId: 3b5e5bc6888326f8a6d615c3272cdf66aa285987
1 parent 04c3b44 commit 57027e6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/server/impl/query_impl.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,15 @@ export class QueryImpl implements Query<GenericTableInfo> {
166166
| { type: "executing"; queryId: number }
167167
| { type: "closed" }
168168
| { type: "consumed" };
169+
private tableNameForErrorMessages: string;
169170

170171
constructor(query: SerializedQuery) {
171172
this.state = { type: "preparing", query };
173+
if (query.source.type === "FullTableScan") {
174+
this.tableNameForErrorMessages = query.source.tableName;
175+
} else {
176+
this.tableNameForErrorMessages = query.source.indexName.split(".")[0];
177+
}
172178
}
173179

174180
private takeQuery(): SerializedQuery {
@@ -333,7 +339,7 @@ export class QueryImpl implements Query<GenericTableInfo> {
333339
return null;
334340
}
335341
if (first_two_array.length === 2) {
336-
throw new Error(`unique() query returned more than one result:
342+
throw new Error(`unique() query returned more than one result from table ${this.tableNameForErrorMessages}:
337343
[${first_two_array[0]._id}, ${first_two_array[1]._id}, ...]`);
338344
}
339345
return first_two_array[0];

0 commit comments

Comments
 (0)