Skip to content
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

Better errors when failure to create a symbol object #55

Open
daveraja opened this issue Oct 11, 2021 · 0 comments
Open

Better errors when failure to create a symbol object #55

daveraja opened this issue Oct 11, 2021 · 0 comments

Comments

@daveraja
Copy link
Collaborator

When you create a predicate instance it creates the corresponding underlying clingo.Symbol object. Clorm does not try to validate the input to the predicate but instead lets the clingo API take care of that. So if a user tries to assign to the wrong type (for example, passing a string when you're trying to create an integer symbol) then it is up to the clingo API to deal with it. There are a few issues here:

  1. The CFFI errors that are thrown for a failed conversion are not easy to understand. So I should catch these errors and report back a clearer message of the type conversion failure.

  2. Clorm works with both clingo 5.4 and 5.5. I think clingo 5.4 is more permissive and will try to use Python's duck-typing to generate the correct data type (eg. the string "5" can be converted to number 5). Clingo 5.5 (which uses CFFI) is stricter and will fail such cases. I think it is best to let the clingo API decide these matters so I don't think there is anything I should do; except...

  3. In the noclingo mode where it uses my internal Symbol proxy objects I let Python's duck typing handle trying to make any conversions. So we could potentially get some unexpected behaviours. For example, a main process that uses noclingo mode assigns "5" as a number. Python duck-typing accepts this and creates the proxy symbol object without complaint. However, the value of the predicate parameter is still "5". This object is the serialised and passed to a worker process which is using clingo mode because it will call the solver. So when the object is de-serialised it will try to create a clingo.Symbol object. But this will fail since the conversion from the string "5" to an integer will now fail (if you're using clingo 5.5). So the main process won't detect anything wrong but the worker process will throw an exception. I need to think about this. I'm not sure if it is better to try to do something or to simply document it.

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

No branches or pull requests

1 participant