-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added hint when using function as procedure and vice versa #322
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: f1883b4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
parsedProcedure.rawText, | ||
parsedProcedure, | ||
DiagnosticSeverity.Error, | ||
`Procedure ${parsedProcedure.name} is not present in the database. Did you mean to call the function ${parsedProcedure.name}? Only procedures can be called inside a CALL clause.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better if the error was actionable IMHO:
${parsedProcedure.name} is a function, not a procedure. Did you mean to use the function ${parsedProcedure.name} with a RETURN instead of a CALL clause?
let existsAsProcedure = false; | ||
if (procedureSchema) { | ||
existsAsProcedure = Boolean(procedureSchema[parsedFunction.name]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be rewritten as:
const existsAsProcedure = procedureSchema && Boolean(procedureSchema[parsedFunction.name]);
if ( | ||
caseInsensitiveFunctionInDatabase && | ||
caseInsensitiveFunctionInDatabase.isBuiltIn | ||
functionExistsWithExactName || | ||
(caseInsensitiveFunctionInDatabase && | ||
caseInsensitiveFunctionInDatabase.isBuiltIn) | ||
) { | ||
return undefined; | ||
return true; | ||
} else { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the if:
return functionExistsWithExactName ||
(caseInsensitiveFunctionInDatabase &&
caseInsensitiveFunctionInDatabase.isBuiltIn)
@@ -74,6 +74,42 @@ describe('Functions semantic validation spec', () => { | |||
]); | |||
}); | |||
|
|||
test('Syntax validation error on function used as procedure returns helpful message', () => { | |||
const query = `CALL abs(-50) YIELD *`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be good to add a test to check we are matching case insensitive functions:
CALL ABS(-1)
@@ -59,6 +59,42 @@ meaning that it expects at least 3 arguments of types NODE, STRING, ANY | |||
]); | |||
}); | |||
|
|||
test('Syntax validation error on procedure used as function returns helpful message', () => { | |||
const query = `RETURN apoc.create.uuids(50)`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conversely, we should add a test to check
RETURN APOC.create.uuids(50)
would just say the function is not in the database, but not that the procedure is (because procedures are case sensitive)
Will yield errors like:
CALL abs(-50) YIELD *
-> Procedure abs is not present in the database. Did you mean to call the function abs? Only procedures can be called inside a CALL clause.and
RETURN apoc.create.uuids(50)
-> Function apoc.create.uuids is not present in the database. Did you mean to call the procedure apoc.create.uuids? Procedures must be called inside a CALL clause.Instead of the regular "Procedure/Function is not present in the database"-messages.