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

Uninformative error message when query not found #9

Open
jmmcd opened this issue Oct 22, 2023 · 3 comments
Open

Uninformative error message when query not found #9

jmmcd opened this issue Oct 22, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@jmmcd
Copy link

jmmcd commented Oct 22, 2023

Version: sparql-anything-v0.8.2.jar

This issue is not an important one. It could be a small cosmetic improvement.

When I tried to sa.run() a query as below, it failed because I mistyped the filename, with the error as below. I think the error message could be more informative, eg FileNotFoundError.

In [4]: sa.run(q='query1.sparql')
[main] INFO com.github.sparqlanything.cli.SPARQLAnything - SPARQL anything
---------------------------------------------------------------------------
JavaException                             Traceback (most recent call last)
Cell In[4], line 1
----> 1 sa.run(q='query1.sparql')

File ~\miniconda3\Lib\site-packages\pysparql_anything\sparql_anything.py:30, in SparqlAnything.run(self, **kwargs)
     23 """
     24 The run method replaces the regular command line execution.
     25 @param **kwargs The keyword arguments are the same as the regular
     26     flags for the Sparql Anything CLI, minus the hyphen.
     27 See the User Guide for an example.
     28 """
     29 command = cmd.RunCommand(kwargs, self.receiver)
---> 30 command.execute()

File ~\miniconda3\Lib\site-packages\pysparql_anything\command.py:159, in RunCommand.execute(self)
    157 """ instructions for a run request """
    158 args = super()._combine()
--> 159 self.receiver.main(args)

File ~\miniconda3\Lib\site-packages\pysparql_anything\engine.py:39, in Engine.main(self, args)
     37 def main(self, args):
     38     """ Wrapper for the SPARQL Anything main method. """
---> 39     self.reflection.main(args)

File jnius\\jnius_export_class.pxi:876, in jnius.JavaMethod.__call__()

File jnius\\jnius_export_class.pxi:1059, in jnius.JavaMethod.call_staticmethod()

File jnius\\jnius_utils.pxi:79, in jnius.check_exception()

JavaException: JVM exception occurred: Lexical error at line 1, column 14.  Encountered: <EOF> after prefix "query1.sparql" org.apache.jena.query.QueryParseException
@MarcoR1791 MarcoR1791 self-assigned this Oct 23, 2023
@MarcoR1791 MarcoR1791 added the enhancement New feature or request label Oct 23, 2023
@MarcoR1791
Copy link
Member

Hi James,

I could implement a preliminary check on whether the file exists that returns a FileNotFoundError.

The JavaException however comes from SPARQL Anything and is simply thrown onto the terminal by PySPARQL.

@enridaga Thoughts? Should I go ahead and implement what I suggested above?

@enridaga
Copy link
Member

Actually, the error is not a file not found but a syntax error on the string interpreted as a query. The value for -q is either a file or, if a file does not exist, a valid SPARQL query. In practice, what happens is that the file is not found, therefore the system attempts to execute the string as a query itself, and fails (see the last line Lexical error at line 1, column 14. Encountered: <EOF>). Maybe, a better way would be to catch the error on the SA code and throw a better message (nor file or valid query string provided...).

@jmmcd
Copy link
Author

jmmcd commented Oct 23, 2023

Thank you, it makes sense.

Off-topic - I have PySA running in my code base now instead of running SA.jar from the command-line. It looks like it is going to cut my runtime from about 5 hours to 3 minutes. So I think you have saved a lot of CO2 emissions with this package!

@MarcoR1791 MarcoR1791 removed their assignment Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants