Skip to content

Commit

Permalink
fix: add better error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
psteinroe committed Jun 4, 2024
1 parent ef874a9 commit 0c7817b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-olives-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@supabase-cache-helpers/postgrest-core": patch
---

fix: better error reporting if select query cannot be parsed
22 changes: 14 additions & 8 deletions packages/postgrest-core/src/lib/parse-select-param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@ import { Path } from './query-types';
export const parseSelectParam = (s: string, currentPath?: Path): Path[] => {
s = s.replace(/\s/g, '');

const foreignTables = XRegExp.matchRecursive(
`,${s}`,
',[^,]*\\(',
'\\)',
'g',
{
let result;
try {
result = XRegExp.matchRecursive(`,${s}`, ',[^,]*\\(', '\\)', 'g', {
valueNames: {
'0': null,
'1': 'tableName',
'2': 'selectedColumns',
'3': null,
},
},
).reduce((prev, curr, idx, matches) => {
});
} catch (e) {
const path = currentPath?.path
? `${currentPath?.declaration} with alias ${currentPath?.alias} at path ${currentPath?.path}`
: 'root';
throw new Error(`Unable to parse ${s} at ${path}`, {
cause: e,
});
}

const foreignTables = result.reduce((prev, curr, idx, matches) => {
if (curr.name === 'selectedColumns') {
const name = matches[idx - 1].value.slice(1, -1);
prev = { ...prev, [name]: curr.value };
Expand Down

0 comments on commit 0c7817b

Please sign in to comment.