# HG changeset patch # User Chris Cannam # Date 1456397590 0 # Node ID d094598f84bd0d1c0ea880580f01b0126a90165a # Parent 1dd98a5432cf1fa6bd403c82cac21c7f6cf5585f Better error reporting for transform load (from RDF and XML) diff -r 1dd98a5432cf -r d094598f84bd rdf/RDFTransformFactory.cpp --- 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 transforms; + if (!m_isRDF) return transforms; + std::map uriTransformMap; Nodes tnodes = m_store->match diff -r 1dd98a5432cf -r d094598f84bd rdf/RDFTransformFactory.h --- 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 getTransforms(ProgressReporter *reporter); diff -r 1dd98a5432cf -r d094598f84bd transform/CSVFeatureWriter.cpp --- 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::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; } diff -r 1dd98a5432cf -r d094598f84bd transform/Transform.cpp --- 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; } diff -r 1dd98a5432cf -r d094598f84bd transform/Transform.h --- 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 Transforms;