Skip to content

Commit b990bfd

Browse files
pcaspersjenkins
authored andcommitted
QPR-12349 improve error message so that it is clear which report is causing the problem
1 parent 29b7df6 commit b990bfd

3 files changed

Lines changed: 39 additions & 25 deletions

File tree

OREData/ored/report/csvreport.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ class ReportTypePrinter : public boost::static_visitor<> {
9191
};
9292

9393
CSVFileReport::CSVFileReport(const string& filename, const char sep, const bool commentCharacter, char quoteChar,
94-
const string& nullString, bool lowerHeader,
95-
QuantLib::Size rolloverSize)
94+
const string& nullString, bool lowerHeader, QuantLib::Size rolloverSize)
9695
: filename_(filename), sep_(sep), commentCharacter_(commentCharacter), quoteChar_(quoteChar),
97-
nullString_(nullString), lowerHeader_(lowerHeader), rolloverSize_(rolloverSize), i_(0), fp_(NULL) {
96+
nullString_(nullString), lowerHeader_(lowerHeader), rolloverSize_(rolloverSize), i_(0), fp_(NULL) {
9897
baseFilename_ = filename_;
9998
open();
10099
}
@@ -121,7 +120,8 @@ void CSVFileReport::rollover() {
121120
version_++;
122121
boost::filesystem::path p(baseFilename_);
123122
boost::filesystem::path newFilepath =
124-
p.parent_path() / boost::filesystem::path(p.stem().string() + "_" + to_string(version_) + p.extension().string());
123+
p.parent_path() /
124+
boost::filesystem::path(p.stem().string() + "_" + to_string(version_) + p.extension().string());
125125
filename_ = newFilepath.string();
126126
open();
127127
}
@@ -135,6 +135,7 @@ void CSVFileReport::flush() {
135135
Report& CSVFileReport::addColumn(const string& name, const ReportType& rt, Size precision) {
136136
checkIsOpen("addColumn(" + name + ")");
137137
columnTypes_.push_back(rt);
138+
headers_.push_back(name);
138139
printers_.push_back(ReportTypePrinter(fp_, precision, quoteChar_, nullString_));
139140
if (i_ == 0 && commentCharacter_)
140141
fprintf(fp_, "#");
@@ -162,18 +163,22 @@ Report& CSVFileReport::next() {
162163
}
163164

164165
checkIsOpen("next()");
165-
QL_REQUIRE(i_ == columnTypes_.size(), "Cannot go to next line, only " << i_ << " entries filled");
166+
QL_REQUIRE(i_ == columnTypes_.size(), "Cannot go to next line, only "
167+
<< i_
168+
<< " entries filled, report headers are: " << boost::join(headers_, ","));
166169
fprintf(fp_, "\n");
167170
i_ = 0;
168171
return *this;
169172
}
170173

171174
Report& CSVFileReport::add(const ReportType& rt) {
172175
checkIsOpen("add()");
173-
QL_REQUIRE(i_ < columnTypes_.size(), "No column to add [" << rt << "] to.");
174-
QL_REQUIRE(rt.which() == columnTypes_[i_].which(), "Cannot add value " << rt << " of type " << rt.which()
175-
<< " to column " << i_ << " of type "
176-
<< columnTypes_[i_].which());
176+
QL_REQUIRE(i_ < columnTypes_.size(),
177+
"No column to add [" << rt << "] to, report headers are: " << boost::join(headers_, ","));
178+
QL_REQUIRE(rt.which() == columnTypes_[i_].which(), "Cannot add value "
179+
<< rt << " of type " << rt.which() << " to column " << i_
180+
<< " of type " << columnTypes_[i_].which()
181+
<< ", report headers are: " << boost::join(headers_, ","));
177182

178183
if (i_ != 0)
179184
fprintf(fp_, "%c", sep_);
@@ -197,13 +202,14 @@ void CSVFileReport::end() {
197202
}
198203

199204
QL_REQUIRE(i_ == columnTypes_.size() || i_ == 0, "csv report is finalized with incomplete row, got data for "
200-
<< i_ << " columns out of " << columnTypes_.size());
205+
<< i_ << " columns out of " << columnTypes_.size()
206+
<< ", report headers are: " << boost::join(headers_, ","));
201207
finalized_ = true;
202208
}
203209

204210
void CSVFileReport::checkIsOpen(const std::string& op) const {
205-
QL_REQUIRE(!finalized_,
206-
"CSV file report '" << filename_ << "' is already finalized, can not process operation " << op);
211+
QL_REQUIRE(!finalized_, "CSV file report '" << filename_ << "' is already finalized, can not process operation "
212+
<< op << ", report headers are: " << boost::join(headers_, ","));
207213
}
208214

209215
} // namespace data

OREData/ored/report/csvreport.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class CSVFileReport : public Report {
7676
Size version_ = 0;
7777
FILE* fp_;
7878
bool finalized_ = false;
79+
vector<string> headers_;
7980
};
8081
} // namespace data
8182
} // namespace ore

OREData/ored/report/inmemoryreport.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
1717
*/
1818

19-
#include <ored/report/inmemoryreport.hpp>
19+
#include <ored/report/inmemoryreport.hpp>
2020

2121
namespace ore {
2222
namespace data {
@@ -31,31 +31,36 @@ Report& InMemoryReport::addColumn(const string& name, const ReportType& rt, Size
3131
}
3232

3333
Report& InMemoryReport::next() {
34-
QL_REQUIRE(i_ == headers_.size(), "Cannot go to next line, only " << i_ << " entires filled");
34+
QL_REQUIRE(i_ == headers_.size(), "Cannot go to next line, only " << i_ << " entires filled, report headers are: "
35+
<< boost::join(headers_, ","));
3536
i_ = 0;
3637
return *this;
3738
}
3839

3940
Report& InMemoryReport::add(const ReportType& rt) {
4041
// check type is valid
4142
QL_REQUIRE(i_ < headers_.size(), "No column to add [" << rt << "] to.");
42-
QL_REQUIRE(rt.which() == columnTypes_[i_].which(),
43-
"Cannot add value " << rt << " of type " << rt.which() << " to column " << headers_[i_]
44-
<< " of type " << columnTypes_[i_].which());
43+
QL_REQUIRE(rt.which() == columnTypes_[i_].which(), "Cannot add value "
44+
<< rt << " of type " << rt.which() << " to column "
45+
<< headers_[i_] << " of type " << columnTypes_[i_].which()
46+
<< ", report headers are: " << boost::join(headers_, ","));
4547

4648
data_[i_].push_back(rt);
4749
i_++;
4850
return *this;
4951
}
5052

5153
Report& InMemoryReport::add(const InMemoryReport& report) {
52-
QL_REQUIRE(columns() == report.columns(),
53-
"Cannot combine reports of different sizes (" << columns() << " vs " << report.columns() << ").");
54+
QL_REQUIRE(columns() == report.columns(), "Cannot combine reports of different sizes ("
55+
<< columns() << " vs " << report.columns()
56+
<< "), report headers are: " << boost::join(headers_, ","));
5457
end();
5558
for (Size i = 0; i < columns(); i++) {
5659
string h1 = headers_[i];
5760
string h2 = report.header(i);
58-
QL_REQUIRE(h1 == h2, "Cannot combine reports with different headers (\"" << h1 << "\" and \"" << h2 << "\")");
61+
QL_REQUIRE(h1 == h2, "Cannot combine reports with different headers (\""
62+
<< h1 << "\" and \"" << h2
63+
<< "\"), report headers are: " << boost::join(headers_, ","));
5964
}
6065

6166
if (i_ == headers_.size())
@@ -72,19 +77,21 @@ Report& InMemoryReport::add(const InMemoryReport& report) {
7277
}
7378

7479
void InMemoryReport::end() {
75-
QL_REQUIRE(i_ == headers_.size() || i_ == 0,
76-
"report is finalized with incomplete row, got data for " << i_ << " columns out of " << columns());
80+
QL_REQUIRE(i_ == headers_.size() || i_ == 0, "report is finalized with incomplete row, got data for "
81+
<< i_ << " columns out of " << columns()
82+
<< ", report headers are: " << boost::join(headers_, ","));
7783
}
7884

7985
const vector<Report::ReportType>& InMemoryReport::data(Size i) const {
8086
QL_REQUIRE(data_[i].size() == rows(), "internal error: report column "
81-
<< i << " (" << header(i) << ") contains " << data_[i].size()
82-
<< " rows, expected are " << rows() << " rows.");
87+
<< i << " (" << header(i) << ") contains " << data_[i].size()
88+
<< " rows, expected are " << rows()
89+
<< " rows, report headers are: " << boost::join(headers_, ","));
8390
return data_[i];
8491
}
8592

8693
void InMemoryReport::toFile(const string& filename, const char sep, const bool commentCharacter, char quoteChar,
87-
const string& nullString, bool lowerHeader) {
94+
const string& nullString, bool lowerHeader) {
8895

8996
CSVFileReport cReport(filename, sep, commentCharacter, quoteChar, nullString, lowerHeader);
9097

0 commit comments

Comments
 (0)