Skip to content

Commit e9e5025

Browse files
committed
Improved some error messages.
- DaphneDSLVisitor: made an error message start in lower case for consistency. - Frame: error message in Frame::getColumnIdx() reports the available labels if the given one was not found (only up to five labels to avoid excessive output). - setColLabels-kernel: reports also the numbers of found and given columns, in case of a mismatch. - These improvements make debugging DaphneDSL scripts easier.
1 parent dd3d696 commit e9e5025

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/parser/daphnedsl/DaphneDSLVisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ antlrcpp::Any DaphneDSLVisitor::visitArgExpr(DaphneDSLGrammarParser::ArgExprCont
736736
}
737737
} catch (std::exception &e) {
738738
throw ErrorHandler::compilerError(utils.getLoc(ctx->start), "DSLVisitor",
739-
"Invalid literal value for argument '" + arg + "': " + argValue);
739+
"invalid literal value for argument '" + arg + "': " + argValue);
740740
}
741741

742742
mlir::Value lit = visitLiteral(literalCtx);

src/runtime/local/datastructures/Frame.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,22 @@ class Frame : public Structure {
336336
auto it = labels2idxs.find(label);
337337
if (it != labels2idxs.end())
338338
return it->second;
339-
throw std::runtime_error("column label not found: '" + label + "'");
339+
std::stringstream msg;
340+
msg << "column label not found: '" + label + "', available labels: ";
341+
if (numCols == 0)
342+
msg << "(none) (zero columns)";
343+
else {
344+
const size_t numLabelsPrintMax = 5;
345+
const size_t numLabelsPrint = std::min(numCols, numLabelsPrintMax);
346+
for (size_t i = 0; i < numLabelsPrint; i++) {
347+
msg << '\'' << labels[i] << '\'';
348+
if (i < numLabelsPrint - 1)
349+
msg << ", ";
350+
}
351+
if (numCols > numLabelsPrintMax)
352+
msg << " (plus " << (numCols - numLabelsPrintMax) << " more)";
353+
}
354+
throw std::runtime_error(msg.str());
340355
}
341356

342357
ValueTypeCode getColumnType(size_t idx) const {

src/runtime/local/kernels/SetColLabels.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
inline void setColLabels(Frame *&res, const Frame *arg, const char **labels, size_t numLabels, DCTX(ctx)) {
3434
const size_t numCols = arg->getNumCols();
3535
if (numLabels != numCols)
36-
throw std::runtime_error("the number of given labels does not match "
37-
"the number of columns of the given frame");
36+
throw std::runtime_error("the number of given labels (" + std::to_string(numLabels) +
37+
") does not match the number of columns of the given frame (" +
38+
std::to_string(numCols) + ")");
3839
std::string *labelsStr = new std::string[numCols];
3940
for (size_t c = 0; c < numCols; c++)
4041
labelsStr[c] = labels[c];

0 commit comments

Comments
 (0)