Skip to content

Improve error message on function argument type mismatch#2813

Open
nafraf wants to merge 33 commits intoRedisGraph:masterfrom
nafraf:enhancement#2802
Open

Improve error message on function argument type mismatch#2813
nafraf wants to merge 33 commits intoRedisGraph:masterfrom
nafraf:enhancement#2802

Conversation

@nafraf
Copy link
Copy Markdown
Contributor

@nafraf nafraf commented Jan 4, 2023

This PR implements #2802

A new function Error_FunctionArgumentSITypeMismatch() was implemented, and additionally to SIValue received and expected type (used in function Error_SITypeMismatch()) it receives function name, argument number and element number.

The function AR_HAS_LABELS() was modified to validate all the input arguments before start to iterate the labels.

These are some examples of the new error messages:

127.0.0.1:6379> graph.query g "CREATE (n:Person {name:'Juan', Age:44} ) RETURN hasLabels(n, ['Person','a',3])"
(error) Type mismatch on function 'hasLabels' argument 2, element 3: expected String but was Integer
127.0.0.1:6379> GRAPH.QUERY g "RETURN subString('abcde', 2, 'z')"
(error) Type mismatch on function 'substring' argument 3: expected Integer but was String

I'm not sure if arithmetic operators, should be considered as an special case:

127.0.0.1:6379> graph.query g "RETURN 2-'a'"
(error) Type mismatch on function 'sub' argument 2: expected Integer, Float, or Null but was String
127.0.0.1:6379> graph.query g "RETURN 2*'a'"
(error) Type mismatch on function 'mul' argument 2: expected Integer, Float, or Null but was String

@nafraf nafraf changed the title Enhancement#2802 Improve error message on function argument type mismatch Jan 4, 2023
@LiorKogan
Copy link
Copy Markdown
Member

Cool!

As for operators, I think a message such as

(error) Type mismatch on function 'sub' argument 2: expected Integer, Float, or Null but was String

may be confusing for the user because s/he didn't call any function.

A better message may be

(error) Type mismatch on operator '-' argument 2: expected Integer, Float, or Null but was String

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 5, 2023

Codecov Report

Base: 90.06% // Head: 90.07% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (69d245c) compared to base (a24a191).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2813   +/-   ##
=======================================
  Coverage   90.06%   90.07%           
=======================================
  Files         270      270           
  Lines       26153    26176   +23     
=======================================
+ Hits        23556    23577   +21     
- Misses       2597     2599    +2     
Impacted Files Coverage Δ
src/arithmetic/arithmetic_expression.c 94.06% <100.00%> (ø)
src/arithmetic/arithmetic_expression_construct.c 93.68% <100.00%> (ø)
src/arithmetic/boolean_funcs/boolean_funcs.c 98.47% <100.00%> (ø)
src/arithmetic/entity_funcs/entity_funcs.c 96.66% <100.00%> (-0.90%) ⬇️
src/errors.c 86.36% <100.00%> (+9.89%) ⬆️
src/value.c 87.46% <100.00%> (-0.48%) ⬇️
src/graph/rg_matrix/rg_set_element_uint64.c 89.36% <0.00%> (-8.52%) ⬇️
src/procedures/proc_ss_paths.c 91.27% <0.00%> (-0.30%) ⬇️
... and 4 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@nafraf
Copy link
Copy Markdown
Contributor Author

nafraf commented Jan 11, 2023

Hi, What is the expected message for this case? operator or any other?

graph.query g "CREATE p=(a)-[r:R]->(b)"
graph.query g "MATCH p=() RETURN p.name"
(error) Type mismatch on function 'property' argument 1: expected Map, Node, Edge, Null, or Point but was Path

@LiorKogan
Copy link
Copy Markdown
Member

I think the following error message would be clear:

(error) Type mismatch on operator '.' left argument: expected Map, Node, Edge, Null, or Point but was Path

Can we please change the order, so 'Null' would always be the last?

(error) Type mismatch on operator '.' left argument: expected Map, Node, Edge, Point, or Null but was Path


This makes me think again about your previous question regarding binary operators: Instead of

(error) Type mismatch on operator '-' argument 2: expected Integer, Float, or Null but was String

It would be better to have a similar error as well:

(error) Type mismatch on operator '-' right argument: expected Integer, Float, or Null but was String

Also for unary operators: RETURN -'a'

(error) Type mismatch on operator '-' right argument: expected Integer, Float, or Null but was String

@nafraf
Copy link
Copy Markdown
Contributor Author

nafraf commented Jan 13, 2023

OK, changes were implemented:

  1. Print Null at last position
127.0.0.1:6379> graph.query g "MERGE p=() RETURN p.name"
(error) Type mismatch on operator '.' left argument: expected Map, Node, Edge, Point, or Null but was Path
  1. Message for binary operators:
127.0.0.1:6379> graph.query g "RETURN 'a'/1"
(error) Type mismatch on operator '/' left argument: expected Integer, Float, or Null but was String
127.0.0.1:6379> graph.query g "RETURN 1%'a'"
(error) Type mismatch on operator '%' right argument: expected Integer, Float, or Null but was String
  1. Message for unary operator:
127.0.0.1:6379> graph.query g "RETURN -'a'"
(error) Type mismatch on operator '-' right argument: expected Integer, Float, or Null but was String

@nafraf nafraf marked this pull request as ready for review January 13, 2023 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants