| 1 | package Net::Async::MCP::JSONRPC; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: How the transports read the error of a JSON-RPC response | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # The message alone cannot carry a code to switch on or an error->{data} to | ||||||||||||||||||||||||||||
| 11 | # read, so the raw error object travels with it as the details of a failure in | ||||||||||||||||||||||||||||
| 12 | # category "mcp". The message stays the first element, so a caller reading the | ||||||||||||||||||||||||||||
| 13 | # failure in scalar context sees exactly what it saw before. Not every "error" | ||||||||||||||||||||||||||||
| 14 | # is a JSON-RPC one: an MCP server answers a bad HTTP method with | ||||||||||||||||||||||||||||
| 15 | # {error => 'Method not allowed'}, a gateway may invent its own shape and a | ||||||||||||||||||||||||||||
| 16 | # foreign stdio server may write anything, so the shape is checked before it | ||||||||||||||||||||||||||||
| 17 | # is read as an object. | ||||||||||||||||||||||||||||
| 18 | 53 | ▶ | sub error_failure { | ||||||||||||||||||||||||||
|
Subroutine
error_failure: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 53 | my ( $self, $response ) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 53 | ▶ | return () unless ref $response eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 49 | my $err = $response->{error}; | |||||||||||||||||||||||||||
| 24 | 49 | ▶ | return () unless ref $err eq 'HASH' && defined $err->{code}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $err eq "HASH" and defined $err->{"code"}
MC/DC100%2/2
ref $err eq "HASH" and defined $err->{"code"}
ref $err eq "HASH"
defined $err->{"code"}
Truth table100%3/3
A and B
A= ref $err eq "HASH"B= defined $err->{"code"}
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | return ( | ||||||||||||||||||||||||||||
| 27 | 35 | ▶ | 'MCP error '.$err->{code}.': '.($err->{message} // '(no message)'), | ||||||||||||||||||||||||||
|
Condition100%2/2
$err->{"message"} // "(no message)"
MC/DC100%1/1
$err->{"message"} // "(no message)"
$err->{"message"}
Truth table100%2/2
A
A= $err->{"message"}
| |||||||||||||||||||||||||||||
| 28 | mcp => $err, | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 13 | ▶ | sub error_text { | ||||||||||||||||||||||||||
|
Subroutine
error_text: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 13 | my ( $self, $err ) = @_; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 13 | ▶ | return $err unless ref $err; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 4 | ▶ | return eval { | ||||||||||||||||||||||||||
|
Condition50%1/2
eval {
do {
"JSON::MaybeXS"->new("utf8", 1, "canonical", 1, "convert_blessed", 1)->encode($err)
}
} // "unknown error"
MC/DC0%0/1
eval {
do {
"JSON::MaybeXS"->new("utf8", 1, "canonical", 1, "convert_blessed", 1)->encode($err)
}
} // "unknown error"
eval {
do {
"JSON::MaybeXS"->new("utf8", 1, "canonical", 1, "convert_blessed", 1)->encode($err)
}
}
Truth table50%1/2
A
A= eval {
do {
"JSON::MaybeXS"->new("utf8", 1, "canonical", 1, "convert_blessed", 1)->encode($err)
}
}
| |||||||||||||||||||||||||||||
| 38 | 4 | JSON::MaybeXS->new(utf8 => 1, canonical => 1, convert_blessed => 1)->encode($err) | |||||||||||||||||||||||||||
| 39 | } // 'unknown error'; | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 11 | 1; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | __END__ | ||||||||||||||||||||||||||||