Coverage Report

Created: 2025-11-01 07:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/duckdb/src/common/exception/binder_exception.cpp
Line
Count
Source
1
#include "duckdb/common/exception/binder_exception.hpp"
2
#include "duckdb/common/string_util.hpp"
3
#include "duckdb/function/function.hpp"
4
5
namespace duckdb {
6
7
824
BinderException::BinderException(const string &msg) : Exception(ExceptionType::BINDER, msg) {
8
824
}
9
10
BinderException::BinderException(const unordered_map<string, string> &extra_info, const string &msg)
11
135k
    : Exception(extra_info, ExceptionType::BINDER, msg) {
12
135k
}
13
14
BinderException BinderException::ColumnNotFound(const string &name, const vector<string> &similar_bindings,
15
134k
                                                QueryErrorContext context) {
16
134k
  auto extra_info = Exception::InitializeExtraInfo("COLUMN_NOT_FOUND", context.query_location);
17
134k
  string candidate_str = StringUtil::CandidatesMessage(similar_bindings, "Candidate bindings");
18
134k
  extra_info["name"] = name;
19
134k
  if (!similar_bindings.empty()) {
20
90.5k
    extra_info["candidates"] = StringUtil::Join(similar_bindings, ",");
21
90.5k
  }
22
134k
  return BinderException(
23
134k
      extra_info, StringUtil::Format("Referenced column \"%s\" not found in FROM clause!%s", name, candidate_str));
24
134k
}
25
26
BinderException BinderException::NoMatchingFunction(const string &catalog_name, const string &schema_name,
27
                                                    const string &name, const vector<LogicalType> &arguments,
28
976
                                                    const vector<string> &candidates) {
29
976
  auto extra_info = Exception::InitializeExtraInfo("NO_MATCHING_FUNCTION", optional_idx());
30
  // no matching function was found, throw an error
31
976
  string call_str = Function::CallToString(catalog_name, schema_name, name, arguments);
32
976
  string candidate_str;
33
13.3k
  for (auto &candidate : candidates) {
34
13.3k
    candidate_str += "\t" + candidate + "\n";
35
13.3k
  }
36
976
  extra_info["name"] = name;
37
976
  if (!catalog_name.empty()) {
38
976
    extra_info["catalog"] = catalog_name;
39
976
  }
40
976
  if (!schema_name.empty()) {
41
976
    extra_info["schema"] = schema_name;
42
976
  }
43
976
  extra_info["call"] = call_str;
44
976
  if (!candidates.empty()) {
45
976
    extra_info["candidates"] = StringUtil::Join(candidates, ",");
46
976
  }
47
976
  return BinderException(
48
976
      extra_info,
49
976
      StringUtil::Format("No function matches the given name and argument types '%s'. You might need to add "
50
976
                         "explicit type casts.\n\tCandidate functions:\n%s",
51
976
                         call_str, candidate_str));
52
976
}
53
54
447
BinderException BinderException::Unsupported(ParsedExpression &expr, const string &message) {
55
447
  auto extra_info = Exception::InitializeExtraInfo("UNSUPPORTED", expr.GetQueryLocation());
56
447
  return BinderException(extra_info, message);
57
447
}
58
} // namespace duckdb