OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ErrorHandling.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include "enums.h"
20 
21 #include <stdexcept>
22 
23 using heavyai::ErrorCode;
24 
26  heavyai::QueryDescriptionType query_type;
28 };
29 
30 class QueryExecutionError : public std::runtime_error {
31  public:
32  QueryExecutionError(const ErrorCode error_code, const std::string& e)
33  : std::runtime_error(std::string("Query execution failed with error code ") +
34  to_string(error_code) + "\n" + e)
35  , error_code_(static_cast<int32_t>(error_code)) {}
36 
38  const std::string& e,
39  const QueryExecutionProperties& execution_properties)
40  : std::runtime_error(std::string("Query execution failed with error code ") +
41  to_string(error_code) + "\n" + e)
42  , error_code_(static_cast<int32_t>(error_code))
43  , execution_props_(execution_properties) {}
44 
46  const QueryExecutionProperties& execution_properties)
47  : std::runtime_error(std::string("Query execution failed with error code ") +
48  to_string(error_code))
49  , error_code_(static_cast<int32_t>(error_code))
50  , execution_props_(execution_properties) {}
51 
53  : std::runtime_error(std::string("Query execution failed with error code ") +
54  to_string(error_code))
55  , error_code_(static_cast<int32_t>(error_code)) {}
56 
57  // Given error_code may not be in range of enum class ErrorCode.
59  : std::runtime_error("Query execution failed with error code " +
60  QueryExecutionError::toString(error_code))
61  , error_code_(error_code) {}
62 
63  int32_t getErrorCode() const { return error_code_; }
64 
65  bool hasErrorCode(ErrorCode const ec) const {
66  return error_code_ == static_cast<int32_t>(ec);
67  }
68 
69  inline static std::string toString(int32_t error_code) {
70  if (size_t(error_code) < size_t(ErrorCode::N_)) {
71  return to_string(static_cast<ErrorCode>(error_code));
72  } else {
73  return std::to_string(error_code);
74  }
75  }
76 
77  bool wasMultifragKernelLaunch() const {
78  return execution_props_ && (*execution_props_).was_multifrag_kernel_launch;
79  }
80 
81  protected:
82  int32_t error_code_; // May be out-of-range of enum class ErrorCode values.
83  boost::optional<QueryExecutionProperties> execution_props_;
84 };
85 
86 class ReductionRanOutOfSlots : public std::runtime_error {
87  public:
88  ReductionRanOutOfSlots() : std::runtime_error("ReductionRanOutOfSlots") {}
89 };
QueryExecutionError(const ErrorCode error_code, const std::string &e, const QueryExecutionProperties &execution_properties)
Definition: ErrorHandling.h:37
boost::optional< QueryExecutionProperties > execution_props_
Definition: ErrorHandling.h:83
int32_t getErrorCode() const
Definition: ErrorHandling.h:63
static std::string toString(int32_t error_code)
Definition: ErrorHandling.h:69
QueryExecutionError(const int32_t error_code)
Definition: ErrorHandling.h:58
std::string to_string(char const *&&v)
bool hasErrorCode(ErrorCode const ec) const
Definition: ErrorHandling.h:65
QueryExecutionError(const ErrorCode error_code, const QueryExecutionProperties &execution_properties)
Definition: ErrorHandling.h:45
QueryEngine enum classes with minimal #include files.
QueryExecutionError(const ErrorCode error_code)
Definition: ErrorHandling.h:52
heavyai::QueryDescriptionType query_type
Definition: ErrorHandling.h:26
bool wasMultifragKernelLaunch() const
Definition: ErrorHandling.h:77
def error_code
Definition: report.py:234
QueryExecutionError(const ErrorCode error_code, const std::string &e)
Definition: ErrorHandling.h:32