Mercurial > hg > svcore
changeset 1163:d094598f84bd
Better error reporting for transform load (from RDF and XML)
author | Chris Cannam |
---|---|
date | Thu, 25 Feb 2016 10:53:10 +0000 (2016-02-25) |
parents | 1dd98a5432cf |
children | 0f90a357cb2a |
files | rdf/RDFTransformFactory.cpp rdf/RDFTransformFactory.h transform/CSVFeatureWriter.cpp transform/Transform.cpp transform/Transform.h |
diffstat | 5 files changed, 40 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/rdf/RDFTransformFactory.cpp Wed Feb 24 11:35:51 2016 +0000 +++ b/rdf/RDFTransformFactory.cpp Thu Feb 25 10:53:10 2016 +0000 @@ -129,7 +129,12 @@ } m_store->import(qurl, BasicStore::ImportIgnoreDuplicates); m_isRDF = true; - } catch (...) { } + } catch (const std::exception &e) { + // The file is not RDF -- we report this by returning false + // from isRDF (because we have not reached the m_isRDF = true + // line above), but we also set the error string + m_errorString = e.what(); + } } RDFTransformFactoryImpl::~RDFTransformFactoryImpl() @@ -146,7 +151,7 @@ bool RDFTransformFactoryImpl::isOK() { - return (m_errorString == ""); + return m_isRDF && (m_errorString == ""); } QString @@ -160,6 +165,8 @@ { std::vector<Transform> transforms; + if (!m_isRDF) return transforms; + std::map<QString, Transform> uriTransformMap; Nodes tnodes = m_store->match
--- a/rdf/RDFTransformFactory.h Wed Feb 24 11:35:51 2016 +0000 +++ b/rdf/RDFTransformFactory.h Thu Feb 25 10:53:10 2016 +0000 @@ -36,8 +36,28 @@ RDFTransformFactory(QString url); virtual ~RDFTransformFactory(); - bool isRDF(); // true if the file was parseable and had transforms in it - bool isOK(); // true if the transforms could be completely constructed + /** isRDF() may be queried at any point after construction. It + returns true if the file was parseable as RDF. + */ + bool isRDF(); + + /** isOK() may be queried at any point after getTransforms() has + been called. It is true if the file was parseable as RDF and + any transforms in it could be completely constructed. + + Note that even if isOK() returns true, it is still possible + that the file did not define any transforms; in this case, + getTransforms() would have returned an empty list. + + If isOK() is called before getTransforms() has been invoked to + query the file, it will return true iff isRDF() is true. + */ + bool isOK(); + + /** Return any error string resulting from loading or querying the + file. This will be non-empty if isRDF() or isOK() returns + false. + */ QString getErrorString() const; std::vector<Transform> getTransforms(ProgressReporter *reporter);
--- a/transform/CSVFeatureWriter.cpp Wed Feb 24 11:35:51 2016 +0000 +++ b/transform/CSVFeatureWriter.cpp Thu Feb 25 10:53:10 2016 +0000 @@ -99,10 +99,10 @@ SVDEBUG << "CSVFeatureWriter::setParameters" << endl; for (map<string, string>::iterator i = params.begin(); i != params.end(); ++i) { - cerr << i->first << " -> " << i->second << endl; + SVDEBUG << i->first << " -> " << i->second << endl; if (i->first == "separator") { m_separator = i->second.c_str(); - cerr << "m_separator = " << m_separator << endl; + SVDEBUG << "m_separator = " << m_separator << endl; if (m_separator == "\\t") { m_separator = QChar::Tabulation; }
--- a/transform/Transform.cpp Wed Feb 24 11:35:51 2016 +0000 +++ b/transform/Transform.cpp Thu Feb 25 10:53:10 2016 +0000 @@ -54,12 +54,8 @@ int errorColumn; if (!doc.setContent(xml, false, &error, &errorLine, &errorColumn)) { - cerr << "Transform::Transform: Error in parsing XML: " - << error << " at line " << errorLine - << ", column " << errorColumn << endl; - cerr << "Input follows:" << endl; - cerr << xml << endl; - cerr << "Input ends." << endl; + m_errorString = QString("%1 at line %2, column %3") + .arg(error).arg(errorLine).arg(errorColumn); return; }
--- a/transform/Transform.h Wed Feb 24 11:35:51 2016 +0000 +++ b/transform/Transform.h Thu Feb 25 10:53:10 2016 +0000 @@ -46,7 +46,8 @@ /** * Construct a Transform by parsing the given XML data string. - * This is the inverse of toXml. + * This is the inverse of toXml. If this fails, getErrorString() + * will return a non-empty string. */ Transform(QString xml); @@ -156,6 +157,8 @@ */ void setFromXmlAttributes(const QXmlAttributes &); + QString getErrorString() const { return m_errorString; } + static SummaryType stringToSummaryType(QString); static QString summaryTypeToString(SummaryType); @@ -195,6 +198,7 @@ RealTime m_startTime; RealTime m_duration; sv_samplerate_t m_sampleRate; + QString m_errorString; }; typedef std::vector<Transform> Transforms;