Chapter 9: Error Handling

9.1 Error Handling Model

DTP's error handling follows a three-phase "Detect-Notify-Recover" model:

  1. Detect: Identify abnormal conditions
  2. Notify: Send error information to the remote peer or upper layer
  3. Recover: Take recovery measures based on the error type

9.2 Error Code System

DTP defines a unique error code for each error type, divided into eight ranges by functional module:

Error CategoryCode RangeHandling Strategy
Frame Processing Errors1xxxDiscard frame + notify sender + log
Encryption Errors2xxxDiscard frame + notify sender + may trigger key renegotiation
Agreement Errors3xxxDiscard Fragment + notify sender + may trigger renegotiation
DAG Errors4xxxReject Fragment + notify sender, or cache and wait
Session Errors5xxxAttempt session recovery + if failed, close and notify upper layer
Resume Errors6xxxPause sending + notify upper-layer application
Version Errors7xxxSend version incompatibility notification + attempt downgrade
Permission Errors8xxxReject operation + notify requestor

9.3 Error Code Reference

Frame Processing Errors (1xxx)

Error CodeNameDescription
1001FRAME_DESERIALIZATION_FAILEDFrame deserialization failed
1002FRAME_INVALID_FORMATInvalid frame format

Encryption Errors (2xxx)

Error CodeNameDescription
2001DECRYPTION_FAILEDPayload decryption failed
2002KEY_NOT_READYKey not ready (CAP not completed)

Agreement Errors (3xxx)

Error CodeNameDescription
3001AGREEMENT_NOT_FOUNDAgreement not found
3002AGREEMENT_EXPIREDAgreement expired
3003AGREEMENT_NEGOTIATION_FAILEDAgreement negotiation failed

DAG Errors (4xxx)

Error CodeNameDescription
4001DAG_CYCLE_DETECTEDDAG cycle detected
4002DAG_DEPENDENCY_UNRESOLVEDDAG dependency unresolved

Session Errors (5xxx)

Error CodeNameDescription
5001SESSION_NOT_FOUNDSession not found
5002SESSION_TIMEOUTSession timeout
5003SESSION_RESTORE_FAILEDSession restore failed

Resume Errors (6xxx)

Error CodeNameDescription
6001BUFFER_FULLBuffer full
6002RETRANSMISSION_TIMEOUTRetransmission timeout

Version Errors (7xxx)

Error CodeNameDescription
7001VERSION_INCOMPATIBLEVersion incompatible

Permission Errors (8xxx)

Error CodeNameDescription
8001PERMISSION_DENIEDPermission denied
8002OBSERVER_WRITE_DENIEDObserver write operation denied

9.4 Error Notification Mechanism

Error notifications are conveyed via Control Frames, containing the following information:

FieldDescription
errorCodeError code
errorMessageError description message
relatedFrameIdID of the frame that triggered the error (optional)
relatedAgreementIdRelated Agreement ID (optional)
detailsAdditional details (optional)

9.5 Key Error Scenarios

Deserialization Failure

When a received Logical_Frame cannot be correctly deserialized:

  1. Discard the frame
  2. Send a FRAME_DESERIALIZATION_FAILED (1001) error notification to the sender

Decryption Failure

When a received Logical_Frame's payload cannot be correctly decrypted:

  1. Discard the frame
  2. Send a DECRYPTION_FAILED (2001) error notification to the sender
  3. If consecutive failures exceed the threshold, trigger CAP key renegotiation

DAG Cycle Detection

When a Fragment's declared dependency relationships would form a cycle in the DAG:

  1. Reject the Fragment
  2. Return a DAG_CYCLE_DETECTED (4001) error

Unknown Agreement

When a Fragment references an Agreement_ID that does not exist on the receiver:

  1. Discard the Fragment
  2. Return an AGREEMENT_NOT_FOUND (3001) error

Key Not Ready

When an attempt is made to send data but CAP key exchange has not yet completed:

  1. Refuse to send
  2. Return a KEY_NOT_READY (2002) error to the upper-layer caller

Buffer Full

When the sender's unacknowledged Fragment cache reaches its capacity limit:

  1. Pause sending new Fragments
  2. Send a BUFFER_FULL (6001) notification to the upper-layer application

Observer Privilege Violation

When an Observer attempts to initiate a request or modify an agreement:

  1. Reject the operation
  2. Return an OBSERVER_WRITE_DENIED (8002) error