1 /*
2 * RErrorCategory.hpp
3 *
4 * Copyright (C) 2021 by RStudio, PBC
5 *
6 * Unless you have received this program directly from RStudio pursuant
7 * to the terms of a commercial license agreement with RStudio, then
8 * this program is licensed to you under the terms of version 3 of the
9 * GNU Affero General Public License. This program is distributed WITHOUT
10 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13 *
14 */
15
16 #ifndef R_R_ERROR_CATEGORY_HPP
17 #define R_R_ERROR_CATEGORY_HPP
18
19 #include <boost/system/error_code.hpp>
20
21 namespace rstudio {
22 namespace r {
23 namespace errc {
24
25 enum errc_t {
26 Success = 0,
27 RHomeNotFound,
28 UnsupportedLocale,
29 ExpressionParsingError,
30 CodeExecutionError,
31 SymbolNotFoundError,
32 ListElementNotFoundError,
33 UnexpectedDataTypeError,
34 NoDataAvailableError,
35 AttributeNotFoundError
36 };
37
38 } // namespace errc
39 } // namespace r
40 } // namespace rstudio
41
42
43 namespace RSTUDIO_BOOST_NAMESPACE {
44 namespace system {
45 template <>
46 struct is_error_code_enum<rstudio::r::errc::errc_t>
47 { static const bool value = true; };
48 } // namespace system
49 } // namespace boost
50
51
52
53 #include <shared_core/Error.hpp>
54
55 namespace rstudio {
56 namespace r {
57
58 const boost::system::error_category& rCategory();
59
60 namespace errc {
61
make_error_code(errc_t e)62 inline boost::system::error_code make_error_code( errc_t e )
63 {
64 return boost::system::error_code( e, rCategory() ); }
65
make_error_condition(errc_t e)66 inline boost::system::error_condition make_error_condition( errc_t e )
67 {
68 return boost::system::error_condition( e, rCategory() );
69 }
70
71 } // namespace errc
72
73
74 core::Error rCodeExecutionError(const std::string& errMsg,
75 const core::ErrorLocation& location);
76
77 bool isCodeExecutionError(const core::Error& error,
78 std::string* pErrMsg = nullptr);
79
80 // use the error message generated by R for code execution errors,
81 // otherwise use error.message()
82 std::string endUserErrorMessage(const core::Error& error);
83
84
85 } // namespace r
86 } // namespace rstudio
87
88
89 #endif // R_R_ERROR_CATEGORY_HPP
90
91