FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/core/Error.cpp at master · andschar/rstudio · GitHub
andschar
/
rstudio
Public
forked from
rstudio/rstudio
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
rstudio
/
src
/
cpp
/
core
/
Error.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
326 lines (266 loc) · 6.79 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
core
/
Error.cpp
Copy path
File metadata and controls
326 lines (266 loc) · 6.79 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
* Error.cpp
*
* Copyright (C) 2009-12 by RStudio, Inc.
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#
include
<
ostream
>
#
include
<
sstream
>
#
include
<
core/Error.hpp
>
#
include
<
core/FilePath.hpp
>
#
include
<
core/SafeConvert.hpp
>
#
include
<
boost/lexical_cast.hpp
>
#
ifdef
_WIN32
#
include
<
boost/system/windows_error.hpp
>
#
endif
namespace
rstudio
{
namespace
core
{
struct
Error
::Impl
{
boost::system::error_code ec ;
ErrorProperties properties ;
Error cause ;
ErrorLocation location ;
};
Error::Error
()
: pImpl_()
{
}
Error::Error
(
const
boost::system::error_code& ec,
const
ErrorLocation& location)
: pImpl_(
new
Impl())
{
pImpl_->
ec
= ec ;
pImpl_->
location
= location ;
}
Error::Error
(
const
boost::system::error_code& ec,
const
Error& cause,
const
ErrorLocation& location)
: pImpl_(
new
Impl())
{
pImpl_->
ec
= ec ;
pImpl_->
cause
= cause ;
pImpl_->
location
= location ;
}
Error::~Error
()
{
}
void
Error::copyOnWrite
()
{
if
( (pImpl_.
get
() !=
NULL
) && !pImpl_.
unique
())
{
Impl* pOldImpl = pImpl_.
get
() ;
pImpl_ = boost::shared_ptr<Impl>(
new
Impl
(*pOldImpl)) ;
}
}
const
boost::system::error_code&
Error::code
()
const
{
return
impl
().
ec
;
}
std::string
Error::summary
()
const
{
std::ostringstream ostr;
ostr <<
code
().
category
().
name
() <<
"
error
"
<<
code
().
value
() <<
"
(
"
<<
code
().
message
() <<
"
)
"
;
return
ostr.
str
();
}
const
Error&
Error::cause
()
const
{
return
impl
().
cause
;
}
const
ErrorLocation&
Error::location
()
const
{
return
impl
().
location
;
}
void
Error::addProperty
(
const
std::string& name,
const
std::string& value)
{
copyOnWrite
() ;
impl
().
properties
.
push_back
(
std::make_pair
(name, value)) ;
}
void
Error::addProperty
(
const
std::string& name,
const
FilePath& value)
{
addProperty
(name, value.
absolutePath
());
}
void
Error::addProperty
(
const
std::string& name,
int
value)
{
addProperty
(name,
safe_convert::numberToString
(value));
}
#
define
kErrorExpected
"
expected
"
#
define
kErrorExpectedValue
"
yes
"
void
Error::setExpected
()
{
addProperty
(
kErrorExpected
,
kErrorExpectedValue
);
}
bool
Error::expected
()
const
{
return
getProperty
(
kErrorExpected
) ==
kErrorExpectedValue
;
}
const
std::vector<std::pair<std::string,std::string> >&
Error::properties
()
const
{
return
impl
().
properties
;
}
std::string
Error::getProperty
(
const
std::string& name)
const
{
for
(ErrorProperties::const_iterator it =
properties
().
begin
();
it !=
properties
().
end
(); ++it)
{
if
(it->
first
== name)
return
it->
second
;
}
return
std::string
();
}
bool
Error::isError
()
const
{
if
( pImpl_.
get
() !=
NULL
)
return
pImpl_->
ec
.
value
() !=
0
;
else
return
false
;
}
Error::Impl&
Error::impl
()
const
{
if
(pImpl_.
get
() ==
NULL
)
pImpl_.
reset
(
new
Impl
()) ;
return
*pImpl_ ;
}
Error
systemError
(
int
value,
const
ErrorLocation& location)
{
using
namespace
boost
::system
;
return
Error
(
error_code
(value,
get_system_category
()), location);
}
Error
systemError
(
int
value,
const
Error& cause,
const
ErrorLocation& location)
{
using
namespace
boost
::system
;
return
Error
(
error_code
(value,
get_system_category
()), cause, location);
}
Error
systemError
(
int
value,
const
std::string& description,
const
ErrorLocation& location)
{
Error error =
systemError
(value, location);
error.
addProperty
(
"
description
"
, description);
return
error;
}
Error
fileExistsError
(
const
ErrorLocation& location)
{
#
ifdef
_WIN32
return
systemError
(boost::system::windows_error::file_exists, location);
#
else
return
systemError
(boost::system::errc::file_exists, location);
#
endif
}
Error
fileNotFoundError
(
const
ErrorLocation& location)
{
#
ifdef
_WIN32
return
systemError
(boost::system::windows_error::file_not_found, location);
#
else
return
systemError
(boost::system::errc::no_such_file_or_directory, location);
#
endif
}
Error
fileNotFoundError
(
const
std::string& path,
const
ErrorLocation& location)
{
Error error =
fileNotFoundError
(location);
error.
addProperty
(
"
path
"
, path);
return
error;
}
Error
fileNotFoundError
(
const
FilePath& filePath,
const
ErrorLocation& location)
{
Error error =
fileNotFoundError
(location);
error.
addProperty
(
"
path
"
, filePath);
return
error;
}
bool
isPathNotFoundError
(
const
Error& error)
{
#
ifdef
_WIN32
return
error.
code
() == boost::system::windows_error::path_not_found;
#
else
return
error.
code
() == boost::system::errc::no_such_file_or_directory;
#
endif
}
Error
pathNotFoundError
(
const
ErrorLocation& location)
{
#
ifdef
_WIN32
return
systemError
(boost::system::windows_error::path_not_found, location);
#
else
return
systemError
(boost::system::errc::no_such_file_or_directory, location);
#
endif
}
Error
pathNotFoundError
(
const
std::string& path,
const
ErrorLocation& location)
{
Error error =
pathNotFoundError
(location);
error.
addProperty
(
"
path
"
, path);
return
error;
}
struct
ErrorLocation
::Impl
{
Impl
() : line(
0
)
{
}
Impl
(
const
char
* function,
const
char
* file,
long
line)
: function(function), file(file), line(line)
{
}
std::string function ;
std::string file ;
long
line ;
};
ErrorLocation::ErrorLocation
()
: pImpl_(
new
Impl())
{
}
ErrorLocation::ErrorLocation
(
const
char
* function,
const
char
* file,
long
line)
: pImpl_(
new
Impl(function, file, line))
{
}
ErrorLocation::~ErrorLocation
()
{
}
bool
ErrorLocation::hasLocation
()
const
{
return
line
() >
0
;
}
const
std::string&
ErrorLocation::function
()
const
{
return
pImpl_->
function
;
}
const
std::string&
ErrorLocation::file
()
const
{
return
pImpl_->
file
;
}
long
ErrorLocation::line
()
const
{
return
pImpl_->
line
;
}
std::string
ErrorLocation::asString
()
const
{
std::ostringstream ostr ;
ostr << *
this
;
return
ostr.
str
();
}
bool
ErrorLocation::
operator
==(
const
ErrorLocation& location)
const
{
return
function
() == location.
function
() &&
file
() == location.
file
() &&
line
() == location.
line
();
}
std::ostream&
operator
<<(std::ostream& os,
const
ErrorLocation& location)
{
os << location.
function
() <<
"
"
<< location.
file
() <<
"
:
"
<< location.
line
() ;
return
os;
}
}
//
namespace core
}
//
namespace rstudio
Back
|
FazBrowse Home
|
New Git URL