feat: hint function names/parameters on error

This commit is contained in:
Laurence Isla
2023-02-02 03:30:15 -05:00
committed by Steve Chavez
parent a525790c4c
commit fd24a7374b
6 changed files with 104 additions and 19 deletions
+31 -9
View File
@@ -120,14 +120,36 @@ spec actualPgVersion =
it "should fail with 404 on unknown proc name" $
get "/rpc/fake" `shouldRespondWith` 404
it "should fail with 404 and hint the closest proc on unknown proc name" $
get "/rpc/sayhell" `shouldRespondWith`
[json| {
"hint":"Perhaps you meant to call the function test.sayhello",
"message":"Could not find the test.sayhell function without parameters in the schema cache",
"code":"PGRST202",
"details":null} |]
{ matchStatus = 404
, matchHeaders = [matchContentTypeJson]
}
it "should fail with 404 on unknown proc args" $ do
get "/rpc/sayhello" `shouldRespondWith` 404
get "/rpc/sayhello?any_arg=value" `shouldRespondWith` 404
it "should fail with 404 and hint the closest args on unknown proc args" $
get "/rpc/sayhello?nam=Peter" `shouldRespondWith`
[json| {
"hint":"Perhaps you meant to call the function test.sayhello(name)",
"message":"Could not find the test.sayhello(nam) function in the schema cache",
"code":"PGRST202",
"details":null} |]
{ matchStatus = 404
, matchHeaders = [matchContentTypeJson]
}
it "should not ignore unknown args and fail with 404" $
get "/rpc/add_them?a=1&b=2&smthelse=blabla" `shouldRespondWith`
[json| {
"hint":"If a new function was created in the database with this name and parameters, try reloading the schema cache.",
"hint":"Perhaps you meant to call the function test.add_them(a, b)",
"message":"Could not find the test.add_them(a, b, smthelse) function in the schema cache",
"code":"PGRST202",
"details":null} |]
@@ -141,7 +163,7 @@ spec actualPgVersion =
[json|{}|]
`shouldRespondWith`
[json| {
"hint":"If a new function was created in the database with this name and parameters, try reloading the schema cache.",
"hint":null,
"message":"Could not find the test.sayhello function with a single json or jsonb parameter in the schema cache",
"code":"PGRST202",
"details":null} |]
@@ -152,7 +174,7 @@ spec actualPgVersion =
it "should fail with 404 for overloaded functions with unknown args" $ do
get "/rpc/overloaded?wrong_arg=value" `shouldRespondWith`
[json| {
"hint":"If a new function was created in the database with this name and parameters, try reloading the schema cache.",
"hint":null,
"message":"Could not find the test.overloaded(wrong_arg) function in the schema cache",
"code":"PGRST202",
"details":null} |]
@@ -161,7 +183,7 @@ spec actualPgVersion =
}
get "/rpc/overloaded?a=1&b=2&wrong_arg=value" `shouldRespondWith`
[json| {
"hint":"If a new function was created in the database with this name and parameters, try reloading the schema cache.",
"hint":"Perhaps you meant to call the function test.overloaded(a, b, c)",
"message":"Could not find the test.overloaded(a, b, wrong_arg) function in the schema cache",
"code":"PGRST202",
"details":null} |]
@@ -1251,7 +1273,7 @@ spec actualPgVersion =
[json|{"x": 1, "y": 2}|]
`shouldRespondWith`
[json|{
"hint": "If a new function was created in the database with this name and parameters, try reloading the schema cache.",
"hint": "Perhaps you meant to call the function test.unnamed_text_param",
"message": "Could not find the test.unnamed_int_param(x, y) function or the test.unnamed_int_param function with a single unnamed json or jsonb parameter in the schema cache",
"code":"PGRST202",
"details":null
@@ -1266,7 +1288,7 @@ spec actualPgVersion =
[str|a simple text|]
`shouldRespondWith`
[json|{
"hint": "If a new function was created in the database with this name and parameters, try reloading the schema cache.",
"hint": null,
"message": "Could not find the test.unnamed_int_param function with a single unnamed text parameter in the schema cache",
"code":"PGRST202",
"details":null
@@ -1281,7 +1303,7 @@ spec actualPgVersion =
[str|a simple text|]
`shouldRespondWith`
[json|{
"hint": "If a new function was created in the database with this name and parameters, try reloading the schema cache.",
"hint": null,
"message": "Could not find the test.unnamed_int_param function with a single unnamed xml parameter in the schema cache",
"code":"PGRST202",
"details":null
@@ -1297,7 +1319,7 @@ spec actualPgVersion =
file
`shouldRespondWith`
[json|{
"hint": "If a new function was created in the database with this name and parameters, try reloading the schema cache.",
"hint": null,
"message": "Could not find the test.unnamed_int_param function with a single unnamed bytea parameter in the schema cache",
"code":"PGRST202",
"details":null
@@ -1357,7 +1379,7 @@ spec actualPgVersion =
"a,b\n1,2\n4,6\n100,200"
`shouldRespondWith`
[json| {
"hint":"If a new function was created in the database with this name and parameters, try reloading the schema cache.",
"hint":"Perhaps you meant to call the function test.overloaded_unnamed_param(x, y)",
"message":"Could not find the test.overloaded_unnamed_param(a, b) function in the schema cache",
"code":"PGRST202",
"details":null