Skip to content

Commit 7dd1f59

Browse files
authored
feat: Add Javadoc for the spec module (#466)
Fixes: #475
1 parent 3d6f762 commit 7dd1f59

File tree

95 files changed

+3215
-112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+3215
-112
lines changed

spec/src/main/java/io/a2a/spec/A2AClientError.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
11
package io.a2a.spec;
22

33
/**
4-
* Base exception for A2A Client errors.
4+
* Base exception for A2A client-specific error conditions.
5+
* <p>
6+
* This is a specialized exception hierarchy for client-side errors, distinct from
7+
* {@link A2AClientException}. It is used for errors that occur during client SDK
8+
* operations such as validation, state management, and protocol handling.
9+
* <p>
10+
* Specialized subclasses:
11+
* <ul>
12+
* <li>{@link A2AClientHTTPError} - HTTP transport errors with status codes</li>
13+
* <li>{@link A2AClientJSONError} - JSON serialization/deserialization errors</li>
14+
* <li>{@link A2AClientInvalidStateError} - Invalid client state errors</li>
15+
* <li>{@link A2AClientInvalidArgsError} - Invalid argument errors</li>
16+
* </ul>
17+
*
18+
* @see A2AClientException for general client exceptions
19+
* @see A2AClientHTTPError for HTTP-specific errors
20+
* @see A2AClientJSONError for JSON-specific errors
21+
* @see A2AClientInvalidStateError for invalid state errors
22+
* @see A2AClientInvalidArgsError for invalid argument errors
523
*/
624
public class A2AClientError extends RuntimeException {
25+
/**
26+
* Constructs a new A2AClientError with no detail message.
27+
*/
728
public A2AClientError() {
829
}
930

31+
/**
32+
* Constructs a new A2AClientError with the specified detail message.
33+
*
34+
* @param message the detail message
35+
*/
1036
public A2AClientError(String message) {
1137
super(message);
1238
}
1339

40+
/**
41+
* Constructs a new A2AClientError with the specified detail message and cause.
42+
*
43+
* @param message the detail message
44+
* @param cause the cause of this exception
45+
*/
1446
public A2AClientError(String message, Throwable cause) {
1547
super(message, cause);
1648
}

spec/src/main/java/io/a2a/spec/A2AClientException.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,56 @@
11
package io.a2a.spec;
22

33
/**
4-
* Exception to indicate a general failure related to an A2A client.
4+
* Exception indicating a client-side failure in A2A Protocol operations.
5+
* <p>
6+
* This exception is thrown by A2A client implementations when encountering errors
7+
* during communication with agents, response validation, or client-side processing.
8+
* <p>
9+
* Common scenarios:
10+
* <ul>
11+
* <li>Network communication failures</li>
12+
* <li>Invalid agent responses ({@link A2AClientError})</li>
13+
* <li>HTTP errors ({@link A2AClientHTTPError})</li>
14+
* <li>JSON parsing errors ({@link A2AClientJSONError})</li>
15+
* </ul>
16+
*
17+
* @see A2AException for the base exception class
18+
* @see A2AServerException for server-side errors
19+
* @see A2AClientError for more specific client errors
520
*/
621
public class A2AClientException extends A2AException {
722

23+
/**
24+
* Constructs a new A2AClientException with no detail message or cause.
25+
*/
826
public A2AClientException() {
927
super();
1028
}
1129

30+
/**
31+
* Constructs a new A2AClientException with the specified detail message.
32+
*
33+
* @param msg the detail message
34+
*/
1235
public A2AClientException(final String msg) {
1336
super(msg);
1437
}
1538

39+
/**
40+
* Constructs a new A2AClientException with the specified cause.
41+
*
42+
* @param cause the cause of this exception
43+
*/
1644
public A2AClientException(final Throwable cause) {
1745
super(cause);
1846
}
1947

48+
/**
49+
* Constructs a new A2AClientException with the specified detail message and cause.
50+
*
51+
* @param msg the detail message
52+
* @param cause the cause of this exception
53+
*/
2054
public A2AClientException(final String msg, final Throwable cause) {
2155
super(msg, cause);
2256
}

spec/src/main/java/io/a2a/spec/A2AClientHTTPError.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@
22

33
import io.a2a.util.Assert;
44

5+
/**
6+
* Client exception indicating an HTTP transport error with a specific status code.
7+
* <p>
8+
* This exception is thrown when HTTP communication with an A2A agent fails,
9+
* capturing both the HTTP status code and error message. It is used for non-2xx
10+
* HTTP responses that don't contain valid A2A Protocol error responses.
11+
* <p>
12+
* Common HTTP status codes:
13+
* <ul>
14+
* <li>4xx - Client errors (400 Bad Request, 401 Unauthorized, 404 Not Found, etc.)</li>
15+
* <li>5xx - Server errors (500 Internal Server Error, 503 Service Unavailable, etc.)</li>
16+
* </ul>
17+
* <p>
18+
* Usage example:
19+
* <pre>{@code
20+
* if (response.statusCode() >= 400) {
21+
* throw new A2AClientHTTPError(
22+
* response.statusCode(),
23+
* "HTTP error: " + response.statusMessage(),
24+
* response.body()
25+
* );
26+
* }
27+
* }</pre>
28+
*
29+
* @see A2AClientError for the base client error class
30+
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status">HTTP Status Codes</a>
31+
*/
532
public class A2AClientHTTPError extends A2AClientError {
633
private final int code;
734
private final String message;

spec/src/main/java/io/a2a/spec/A2AClientInvalidArgsError.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
package io.a2a.spec;
22

3+
/**
4+
* Client exception indicating invalid arguments provided to a client operation.
5+
* <p>
6+
* This exception is thrown when parameters passed to A2A client SDK methods fail
7+
* validation. This is distinct from {@link InvalidParamsError}, which represents
8+
* server-side parameter validation errors.
9+
* <p>
10+
* Common scenarios:
11+
* <ul>
12+
* <li>Null values for required parameters</li>
13+
* <li>Invalid parameter combinations</li>
14+
* <li>Parameter values outside acceptable ranges</li>
15+
* <li>Malformed URIs or identifiers</li>
16+
* </ul>
17+
* <p>
18+
* Usage example:
19+
* <pre>{@code
20+
* if (agentUrl == null || agentUrl.isEmpty()) {
21+
* throw new A2AClientInvalidArgsError("agentUrl cannot be null or empty");
22+
* }
23+
* }</pre>
24+
*
25+
* @see A2AClientError for the base client error class
26+
* @see InvalidParamsError for server-side parameter errors
27+
*/
328
public class A2AClientInvalidArgsError extends A2AClientError {
429

530
public A2AClientInvalidArgsError() {

spec/src/main/java/io/a2a/spec/A2AClientInvalidStateError.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
package io.a2a.spec;
22

3+
/**
4+
* Client exception indicating an invalid state for the requested operation.
5+
* <p>
6+
* This exception is thrown when a client operation is attempted while the client
7+
* is in a state that doesn't permit that operation. This ensures proper sequencing
8+
* and lifecycle management of client operations.
9+
* <p>
10+
* Common scenarios:
11+
* <ul>
12+
* <li>Attempting to send messages before client initialization</li>
13+
* <li>Trying to cancel a task after the client connection is closed</li>
14+
* <li>Performing operations on a client that has been shut down</li>
15+
* <li>Violating client state machine transitions</li>
16+
* </ul>
17+
* <p>
18+
* Usage example:
19+
* <pre>{@code
20+
* if (!client.isConnected()) {
21+
* throw new A2AClientInvalidStateError("Client not connected");
22+
* }
23+
* }</pre>
24+
*
25+
* @see A2AClientError for the base client error class
26+
*/
327
public class A2AClientInvalidStateError extends A2AClientError {
428

529
public A2AClientInvalidStateError() {

spec/src/main/java/io/a2a/spec/A2AClientJSONError.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
package io.a2a.spec;
22

3+
/**
4+
* Client exception indicating a JSON serialization or deserialization error.
5+
* <p>
6+
* This exception is thrown when the A2A client SDK encounters errors while
7+
* parsing JSON responses from agents or serializing requests. This typically
8+
* indicates:
9+
* <ul>
10+
* <li>Malformed JSON in agent responses</li>
11+
* <li>Unexpected JSON structure or field types</li>
12+
* <li>Missing required JSON fields</li>
13+
* <li>JSON encoding/decoding errors</li>
14+
* </ul>
15+
* <p>
16+
* Usage example:
17+
* <pre>{@code
18+
* try {
19+
* AgentCard card = objectMapper.readValue(json, AgentCard.class);
20+
* } catch (JsonProcessingException e) {
21+
* throw new A2AClientJSONError("Failed to parse agent card", e);
22+
* }
23+
* }</pre>
24+
*
25+
* @see A2AClientError for the base client error class
26+
* @see JSONParseError for protocol-level JSON errors
27+
*/
328
public class A2AClientJSONError extends A2AClientError {
429

530
public A2AClientJSONError() {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
package io.a2a.spec;
22

3+
/**
4+
* Marker interface for A2A Protocol error events.
5+
* <p>
6+
* This interface extends {@link Event} to allow errors to be transmitted as events
7+
* in the A2A Protocol's event stream. All protocol-level errors implement this interface,
8+
* enabling uniform error handling across both streaming and non-streaming communication.
9+
* <p>
10+
* A2A errors typically extend {@link JSONRPCError} to provide JSON-RPC 2.0 compliant
11+
* error responses with standard error codes, messages, and optional additional data.
12+
* <p>
13+
* Common implementations include:
14+
* <ul>
15+
* <li>{@link InvalidParamsError} - Invalid method parameters</li>
16+
* <li>{@link InvalidRequestError} - Malformed request</li>
17+
* <li>{@link MethodNotFoundError} - Unknown method</li>
18+
* <li>{@link InternalError} - Server-side error</li>
19+
* <li>{@link TaskNotFoundError} - Task does not exist</li>
20+
* <li>And others for specific protocol error conditions</li>
21+
* </ul>
22+
*
23+
* @see Event for the base event interface
24+
* @see JSONRPCError for the base error implementation
25+
* @see <a href="https://www.jsonrpc.org/specification#error_object">JSON-RPC 2.0 Error Object</a>
26+
* @see <a href="https://a2a-protocol.org/latest/">A2A Protocol Specification</a>
27+
*/
328
public interface A2AError extends Event {
429
}

spec/src/main/java/io/a2a/spec/A2AException.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
package io.a2a.spec;
22

33
/**
4-
* Exception to indicate a general failure related to the A2A protocol.
4+
* Base exception for A2A Protocol-related failures.
5+
* <p>
6+
* This is the root exception class for all A2A Protocol exceptions, providing a common
7+
* base type for exception handling. It extends {@link RuntimeException} to allow unchecked
8+
* exception propagation throughout A2A client and server implementations.
9+
* <p>
10+
* Specialized subclasses:
11+
* <ul>
12+
* <li>{@link A2AServerException} - Server-side failures</li>
13+
* <li>{@link A2AClientException} - Client-side failures</li>
14+
* </ul>
15+
*
16+
* @see A2AServerException for server-side errors
17+
* @see A2AClientException for client-side errors
18+
* @see <a href="https://a2a-protocol.org/latest/">A2A Protocol Specification</a>
519
*/
620
public class A2AException extends RuntimeException {
721

spec/src/main/java/io/a2a/spec/A2AServerException.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
package io.a2a.spec;
22

33
/**
4-
* Exception to indicate a general failure related to an A2A server.
4+
* Exception indicating a server-side failure in A2A Protocol operations.
5+
* <p>
6+
* This exception is thrown by A2A server implementations when encountering errors
7+
* during request processing, task execution, or other server-side operations.
8+
* <p>
9+
* Common scenarios:
10+
* <ul>
11+
* <li>Agent execution failures</li>
12+
* <li>Task store persistence errors</li>
13+
* <li>Resource exhaustion or limits exceeded</li>
14+
* <li>Configuration errors</li>
15+
* </ul>
16+
*
17+
* @see A2AException for the base exception class
18+
* @see A2AClientException for client-side errors
519
*/
620
public class A2AServerException extends A2AException {
721

spec/src/main/java/io/a2a/spec/APIKeySecurityScheme.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@
1212
import static io.a2a.spec.APIKeySecurityScheme.API_KEY;
1313

1414
/**
15-
* Defines a security scheme using an API key.
15+
* API key security scheme for agent authentication.
16+
* <p>
17+
* This security scheme uses an API key that can be sent in a header, query parameter,
18+
* or cookie to authenticate requests to the agent.
19+
* <p>
20+
* Corresponds to the OpenAPI "apiKey" security scheme type.
21+
*
22+
* @see SecurityScheme for the base interface
23+
* @see <a href="https://spec.openapis.org/oas/v3.0.0#security-scheme-object">OpenAPI Security Scheme</a>
24+
* @see <a href="https://a2a-protocol.org/latest/">A2A Protocol Specification</a>
1625
*/
1726
@JsonTypeName(API_KEY)
1827
@JsonInclude(JsonInclude.Include.NON_ABSENT)

0 commit comments

Comments
 (0)