fix(error): leaking table and function names when calculating hint

Increase similarity score to 0.75 from 0.33 for table and functions
error hint.

Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
This commit is contained in:
Taimoor Zaeem
2026-03-06 16:03:21 -05:00
committed by Steve Chavez
parent 2861b35f41
commit 5abacba0d8
9 changed files with 66 additions and 21 deletions
+29 -2
View File
@@ -42,10 +42,10 @@ pgErrorCodeMapping = do
it "works with SchemaCache error" $
get "/non_existent_table"
`shouldRespondWith`
[json| {"code":"PGRST205","details":null,"hint":"Perhaps you meant the table 'test.collision_test_table'","message":"Could not find the table 'test.non_existent_table' in the schema cache"} |]
[json| {"code":"PGRST205","details":null,"hint":null,"message":"Could not find the table 'test.non_existent_table' in the schema cache"} |]
{ matchStatus = 404
, matchHeaders = [ "Proxy-Status" <:> "PostgREST; error=PGRST205"
, "Content-Length" <:> "182" ]
, "Content-Length" <:> "129" ]
}
it "works with Jwt error" $ do
@@ -75,3 +75,30 @@ pgErrorCodeMapping = do
, matchHeaders = [ "Proxy-Status" <:> "PostgREST; error=123"
, "Content-Length" <:> "59" ]
}
context "show hint on PGRST205 table not found error" $ do
it "show hint when similarity score is at least 75%" $ do
get "/projectx" -- at least 75% similar to "projects"
`shouldRespondWith`
[json| {"code":"PGRST205","details":null,"hint":"Perhaps you meant the table 'test.projects'","message":"Could not find the table 'test.projectx' in the schema cache"} |]
{ matchStatus = 404
, matchHeaders = [ "Proxy-Status" <:> "PostgREST; error=PGRST205"
, "Content-Length" <:> "160" ]
}
get "/projecxx" -- at least 75% similar to "projects"
`shouldRespondWith`
[json| {"code":"PGRST205","details":null,"hint":"Perhaps you meant the table 'test.projects'","message":"Could not find the table 'test.projecxx' in the schema cache"} |]
{ matchStatus = 404
, matchHeaders = [ "Proxy-Status" <:> "PostgREST; error=PGRST205"
, "Content-Length" <:> "160" ]
}
it "don't show hint when similarity score is less than 75%" $
get "/projxxxx" -- less than 75% similar to "projects"
`shouldRespondWith`
[json| {"code":"PGRST205","details":null,"hint":null,"message":"Could not find the table 'test.projxxxx' in the schema cache"} |]
{ matchStatus = 404
, matchHeaders = [ "Proxy-Status" <:> "PostgREST; error=PGRST205"
, "Content-Length" <:> "119" ]
}