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

Provide ability to get error messages for failures with RDF.to_file #102

Open
jonrkarr opened this issue Jul 19, 2021 · 7 comments
Open
Labels
started Began resolving this issue

Comments

@jonrkarr
Copy link
Contributor

No description provided.

@CiaranWelsh
Copy link
Contributor

Does 28528c8 with the new logging interface resolve this problem? (aka release v.1.2.12?)

@CiaranWelsh CiaranWelsh added the started Began resolving this issue label Aug 20, 2021
@jonrkarr
Copy link
Contributor Author

The log file is much better. Preferably, there would be a log object rather than logging to a file and then parsing that log file.

However, the log file doesn't work for me.

@CiaranWelsh
Copy link
Contributor

The Logger is an object - well collection of static methods really. C++ and Python.

If something isn't working, I'll need code examples to reproduce the problem - thanks.

@jonrkarr
Copy link
Contributor Author

jonrkarr commented Aug 21, 2021

The file logging example at https://sys-bio.github.io/libOmexMeta/docs-build/errors_and_logging/errors_and_logging.html doesn't work for me. The console logger works, but not the file logger.

I used the example exactly, with logger_file = "log.log" and with the CellML edited to be invalid so it should find an error.

# switching to the file logger
from os.path import join, exists, dirname, abspath
from os import remove
from pyomexmeta import RDF, Logger

cellml = '''<?xml version=\"1.1\" encoding=\"UTF-8\"?>
            <model xmlns=\"http://www.cellml.org/cellml/1.1#\" xmlns:cmeta=\"http://www.cellml.org/metadata/1.0#\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:bqs=\"http://www.cellml.org/bqs/1.0#\" xmlns:semsim=\"http://bime.uw.edu/semsim/#\" xmlns:dc=\"http://purl.org/dc/terms/\" xmlns:vCard=\"http://www.w3.org/2001/vcard-rdf/3.0#\" name=\"annotation_examples\" cmeta:id=\"annExamples\">
              <component name=\"main\">
                <variable cmeta:id=\"main.Volume\" initial_value=\"100\" name=\"Volume\" units=\"dimensionless\" />
                <variable cmeta:id=\"main.MembraneVoltage\" initial_value=\"-80\" name=\"MembraneVoltage\" units=\"dimensionless\" />
                <variable cmeta:id=\"main.ReactionRate\" initial_value=\"1\" name=\"ReactionRate\" units=\"dimensionless\" />
              </component>
            </model'''

logger_file = "log.log"
print("check logger_file: " , logger_file)

# if already exists, remove
if exists(logger_file):
    remove(logger_file)
assert not exists(logger_file)

# activate the file logger
Logger.file_logger(logger_file)
rdf = RDF.from_string(cellml, syntax="turtle") # nothing is emitted to console
# now check logger_file

with open(logger_file, 'r') as file:
    print(file.read())

Version: 1.2.12
Python: 3.9.5
OS: Ubuntu

@jonrkarr
Copy link
Contributor Author

I think it would also be helpful to have a error attribute somewhere so that users can at least detect whether there's an error without having to use the file logger.

Right now, I think any user would have to use the file logger unless they were confident that all RDF and all model XML were valid. Then they'd have to read and parse the logs to determine whether there were errors.

@CiaranWelsh
Copy link
Contributor

There is get_last_error Python end, C end but it is currently not being used that much.

It'd be more precise if we could use a code example to illustrate what kind of API you're after - it doesn't matter if the support doesn't exist yet. Also, remember that throwing/raising the errors that come through from reading or serializing is hard since they are logged by the redland libraries. I'm not sure (off the top of my head) how I would convert the C Redland library logging messages into Python or even c++ errors that can be thrown/raised instead of logged.

@jonrkarr
Copy link
Contributor Author

An API that makes it easy to get a list of issues, the level of each issue, and the message associated with each issue would be helpful. This would avoid the need to setup a log file and then parse the log file for errors. I don't have a strong opinion about exactly what this needs to look like.

Methods such as these would be fine:

  • log.get_num_issues()
  • log.get_issue_level(i_message)
  • log.get_issue_message(i_message)

Here's one example from libCellML: https://libcellml.org/documentation/api/v0.2.0/classlibcellml_1_1Logger.
Another is libSBML: http://sbml.org/Software/libSBML/5.18.0/docs/python-api/classlibsbml_1_1_s_b_m_l_error_log.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
started Began resolving this issue
Projects
None yet
Development

No branches or pull requests

2 participants