Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
05620fa8
Commit
05620fa8
authored
Nov 29, 2014
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Throw new 'unimplemented' exception type from unimplemented capability methods.
parent
0af31360
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
10 deletions
+49
-10
capability-test.c++
c++/src/capnp/capability-test.c++
+4
-1
capability.c++
c++/src/capnp/capability.c++
+3
-3
debug.c++
c++/src/kj/debug.c++
+8
-2
debug.h
c++/src/kj/debug.h
+34
-4
No files found.
c++/src/capnp/capability-test.c++
View file @
05620fa8
...
...
@@ -62,6 +62,7 @@ TEST(Capability, Basic) {
[](
Response
<
test
::
TestInterface
::
BarResults
>&&
response
)
{
ADD_FAILURE
()
<<
"Expected bar() call to fail."
;
},
[
&
](
kj
::
Exception
&&
e
)
{
EXPECT_EQ
(
kj
::
Exception
::
Type
::
UNIMPLEMENTED
,
e
.
getType
());
barFailed
=
true
;
});
...
...
@@ -243,6 +244,7 @@ TEST(Capability, DynamicClient) {
[](
Response
<
DynamicStruct
>&&
response
)
{
ADD_FAILURE
()
<<
"Expected bar() call to fail."
;
},
[
&
](
kj
::
Exception
&&
e
)
{
EXPECT_EQ
(
kj
::
Exception
::
Type
::
UNIMPLEMENTED
,
e
.
getType
());
barFailed
=
true
;
});
...
...
@@ -364,7 +366,7 @@ public:
EXPECT_ANY_THROW
(
context
.
getParams
());
return
kj
::
READY_NOW
;
}
else
{
KJ_
FAIL_ASSERT
(
"Method not implemented"
,
methodName
)
{
break
;
}
KJ_
UNIMPLEMENTED
(
"Method not implemented"
,
methodName
)
{
break
;
}
return
kj
::
READY_NOW
;
}
}
...
...
@@ -394,6 +396,7 @@ TEST(Capability, DynamicServer) {
[](
Response
<
test
::
TestInterface
::
BarResults
>&&
response
)
{
ADD_FAILURE
()
<<
"Expected bar() call to fail."
;
},
[
&
](
kj
::
Exception
&&
e
)
{
EXPECT_EQ
(
kj
::
Exception
::
Type
::
UNIMPLEMENTED
,
e
.
getType
());
barFailed
=
true
;
});
...
...
c++/src/capnp/capability.c++
View file @
05620fa8
...
...
@@ -74,7 +74,7 @@ Capability::Client::Client(kj::Exception&& exception)
kj
::
Promise
<
void
>
Capability
::
Server
::
internalUnimplemented
(
const
char
*
actualInterfaceName
,
uint64_t
requestedTypeId
)
{
KJ_
FAIL_REQUIRE
(
"Requested interface not implemented."
,
actualInterfaceName
,
requestedTypeId
)
{
KJ_
UNIMPLEMENTED
(
"Requested interface not implemented."
,
actualInterfaceName
,
requestedTypeId
)
{
// Recoverable exception will be caught by promise framework.
// We can't "return kj::READY_NOW;" inside this block because it causes a memory leak due to
...
...
@@ -88,7 +88,7 @@ kj::Promise<void> Capability::Server::internalUnimplemented(
kj
::
Promise
<
void
>
Capability
::
Server
::
internalUnimplemented
(
const
char
*
interfaceName
,
uint64_t
typeId
,
uint16_t
methodId
)
{
KJ_
FAIL_REQUIRE
(
"Method not implemented."
,
interfaceName
,
typeId
,
methodId
)
{
KJ_
UNIMPLEMENTED
(
"Method not implemented."
,
interfaceName
,
typeId
,
methodId
)
{
// Recoverable exception will be caught by promise framework.
break
;
}
...
...
@@ -97,7 +97,7 @@ kj::Promise<void> Capability::Server::internalUnimplemented(
kj
::
Promise
<
void
>
Capability
::
Server
::
internalUnimplemented
(
const
char
*
interfaceName
,
const
char
*
methodName
,
uint64_t
typeId
,
uint16_t
methodId
)
{
KJ_
FAIL_REQUIRE
(
"Method not implemented."
,
interfaceName
,
typeId
,
methodName
,
methodId
)
{
KJ_
UNIMPLEMENTED
(
"Method not implemented."
,
interfaceName
,
typeId
,
methodName
,
methodId
)
{
// Recoverable exception will be caught by promise framework.
break
;
}
...
...
c++/src/kj/debug.c++
View file @
05620fa8
...
...
@@ -251,12 +251,18 @@ void Debug::Fault::fatal() {
abort
();
}
void
Debug
::
Fault
::
init
(
const
char
*
file
,
int
line
,
Exception
::
Type
type
,
const
char
*
condition
,
const
char
*
macroArgs
,
ArrayPtr
<
String
>
argValues
)
{
exception
=
new
Exception
(
type
,
file
,
line
,
makeDescriptionImpl
(
ASSERTION
,
condition
,
0
,
macroArgs
,
argValues
));
}
void
Debug
::
Fault
::
init
(
const
char
*
file
,
int
line
,
int
osErrorNumber
,
const
char
*
condition
,
const
char
*
macroArgs
,
ArrayPtr
<
String
>
argValues
)
{
exception
=
new
Exception
(
typeOfErrno
(
osErrorNumber
),
file
,
line
,
makeDescriptionImpl
(
osErrorNumber
!=
0
?
SYSCALL
:
ASSERTION
,
condition
,
osErrorNumber
,
macroArgs
,
argValues
));
makeDescriptionImpl
(
SYSCALL
,
condition
,
osErrorNumber
,
macroArgs
,
argValues
));
}
String
Debug
::
makeDescriptionInternal
(
const
char
*
macroArgs
,
ArrayPtr
<
String
>
argValues
)
{
...
...
c++/src/kj/debug.h
View file @
05620fa8
...
...
@@ -144,11 +144,11 @@ namespace kj {
#define KJ_REQUIRE(cond, ...) \
if (KJ_LIKELY(cond)) {} else \
for (::kj::_::Debug::Fault f(__FILE__, __LINE__,
0
, \
for (::kj::_::Debug::Fault f(__FILE__, __LINE__,
::kj::Exception::Type::FAILED
, \
#cond, "" #__VA_ARGS__, __VA_ARGS__);; f.fatal())
#define KJ_FAIL_REQUIRE(...) \
for (::kj::_::Debug::Fault f(__FILE__, __LINE__,
0
, \
for (::kj::_::Debug::Fault f(__FILE__, __LINE__,
::kj::Exception::Type::FAILED
, \
nullptr, "" #__VA_ARGS__, __VA_ARGS__);; f.fatal())
#define KJ_SYSCALL(call, ...) \
...
...
@@ -165,6 +165,10 @@ namespace kj {
for (::kj::_::Debug::Fault f(__FILE__, __LINE__, \
errorNumber, code, "" #__VA_ARGS__, __VA_ARGS__);; f.fatal())
#define KJ_UNIMPLEMENTED(...) \
for (::kj::_::Debug::Fault f(__FILE__, __LINE__, ::kj::Exception::Type::UNIMPLEMENTED, \
nullptr, "" #__VA_ARGS__, __VA_ARGS__);; f.fatal())
#define KJ_CONTEXT(...) \
auto KJ_UNIQUE_NAME(_kjContextFunc) = [&]() -> ::kj::_::Debug::Context::Value { \
return ::kj::_::Debug::Context::Value(__FILE__, __LINE__, \
...
...
@@ -198,11 +202,11 @@ namespace kj {
#define KJ_REQUIRE(cond, ...) \
if (KJ_LIKELY(cond)) {} else \
for (::kj::_::Debug::Fault f(__FILE__, __LINE__,
0
, \
for (::kj::_::Debug::Fault f(__FILE__, __LINE__,
::kj::Exception::Type::FAILED
, \
#cond, #__VA_ARGS__, ##__VA_ARGS__);; f.fatal())
#define KJ_FAIL_REQUIRE(...) \
for (::kj::_::Debug::Fault f(__FILE__, __LINE__,
0
, \
for (::kj::_::Debug::Fault f(__FILE__, __LINE__,
::kj::Exception::Type::FAILED
, \
nullptr, #__VA_ARGS__, ##__VA_ARGS__);; f.fatal())
#define KJ_SYSCALL(call, ...) \
...
...
@@ -219,6 +223,10 @@ namespace kj {
for (::kj::_::Debug::Fault f(__FILE__, __LINE__, \
errorNumber, code, #__VA_ARGS__, ##__VA_ARGS__);; f.fatal())
#define KJ_UNIMPLEMENTED(...) \
for (::kj::_::Debug::Fault f(__FILE__, __LINE__, ::kj::Exception::Type::UNIMPLEMENTED, \
nullptr, #__VA_ARGS__, ##__VA_ARGS__);; f.fatal())
#define KJ_CONTEXT(...) \
auto KJ_UNIQUE_NAME(_kjContextFunc) = [&]() -> ::kj::_::Debug::Context::Value { \
return ::kj::_::Debug::Context::Value(__FILE__, __LINE__, \
...
...
@@ -292,8 +300,13 @@ public:
class
Fault
{
public
:
template
<
typename
...
Params
>
Fault
(
const
char
*
file
,
int
line
,
Exception
::
Type
type
,
const
char
*
condition
,
const
char
*
macroArgs
,
Params
&&
...
params
);
template
<
typename
...
Params
>
Fault
(
const
char
*
file
,
int
line
,
int
osErrorNumber
,
const
char
*
condition
,
const
char
*
macroArgs
,
Params
&&
...
params
);
Fault
(
const
char
*
file
,
int
line
,
Exception
::
Type
type
,
const
char
*
condition
,
const
char
*
macroArgs
);
Fault
(
const
char
*
file
,
int
line
,
int
osErrorNumber
,
const
char
*
condition
,
const
char
*
macroArgs
);
~
Fault
()
noexcept
(
false
);
...
...
@@ -302,6 +315,8 @@ public:
// Throw the exception.
private
:
void
init
(
const
char
*
file
,
int
line
,
Exception
::
Type
type
,
const
char
*
condition
,
const
char
*
macroArgs
,
ArrayPtr
<
String
>
argValues
);
void
init
(
const
char
*
file
,
int
line
,
int
osErrorNumber
,
const
char
*
condition
,
const
char
*
macroArgs
,
ArrayPtr
<
String
>
argValues
);
...
...
@@ -390,6 +405,15 @@ inline void Debug::log<>(const char* file, int line, Severity severity, const ch
logInternal
(
file
,
line
,
severity
,
macroArgs
,
nullptr
);
}
template
<
typename
...
Params
>
Debug
::
Fault
::
Fault
(
const
char
*
file
,
int
line
,
Exception
::
Type
type
,
const
char
*
condition
,
const
char
*
macroArgs
,
Params
&&
...
params
)
:
exception
(
nullptr
)
{
String
argValues
[
sizeof
...(
Params
)]
=
{
str
(
params
)...};
init
(
file
,
line
,
type
,
condition
,
macroArgs
,
arrayPtr
(
argValues
,
sizeof
...(
Params
)));
}
template
<
typename
...
Params
>
Debug
::
Fault
::
Fault
(
const
char
*
file
,
int
line
,
int
osErrorNumber
,
const
char
*
condition
,
const
char
*
macroArgs
,
Params
&&
...
params
)
...
...
@@ -405,6 +429,12 @@ inline Debug::Fault::Fault(const char* file, int line, int osErrorNumber,
init
(
file
,
line
,
osErrorNumber
,
condition
,
macroArgs
,
nullptr
);
}
inline
Debug
::
Fault
::
Fault
(
const
char
*
file
,
int
line
,
kj
::
Exception
::
Type
type
,
const
char
*
condition
,
const
char
*
macroArgs
)
:
exception
(
nullptr
)
{
init
(
file
,
line
,
type
,
condition
,
macroArgs
,
nullptr
);
}
template
<
typename
Call
>
Debug
::
SyscallResult
Debug
::
syscall
(
Call
&&
call
,
bool
nonblocking
)
{
while
(
call
()
<
0
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment