1use super::CallbackError;
2
3#[derive(thiserror::Error, Debug)]
5#[non_exhaustive]
6pub enum Error {
7 #[error("Serialize affine failed")]
9 EccSerializeFailed,
10 #[error("desrialize affine failed")]
12 EccDeserializeFailed,
13 #[error("Failed to initialize Curve hasher")]
15 CurveHasherInitFailed,
16 #[error("Failed to hash data into cruve")]
18 CurveHasherFailed,
19
20 #[error("Ed25519/EdDSA pubkey bad format")]
22 EdDSAPublicKeyBadFormat,
23
24 #[error("Secp256k1/ECDSA pubkey bad format")]
26 ECDSAPublicKeyBadFormat,
27
28 #[error("Failed to lift encoded plaintext into a secp256k1 point")]
30 Secp256k1PointLiftFailed,
31
32 #[error("E2E stream id mismatch: expected {expected}, actual {actual}")]
34 E2eStreamIdMismatch {
35 expected: uuid::Uuid,
37 actual: uuid::Uuid,
39 },
40
41 #[error("E2E frame sequence mismatch: expected {expected}, actual {actual}")]
43 E2eFrameSequenceMismatch {
44 expected: u64,
46 actual: u64,
48 },
49
50 #[error(
52 "E2E frame sequence {actual} exceeds reorder window {window} from next sequence {next_sequence}"
53 )]
54 E2eFrameReorderWindowExceeded {
55 next_sequence: u64,
57 actual: u64,
59 window: u64,
61 },
62
63 #[error("E2E frame sequence counter overflowed")]
65 E2eFrameSequenceOverflow,
66
67 #[error("E2E frame received after the authenticated final frame")]
69 E2eFrameAfterFinal,
70
71 #[error("E2E stream is missing the authenticated final frame")]
73 E2eMissingFinalFrame,
74
75 #[error("E2E public key resolves to {actual}, expected {expected}")]
77 E2ePublicKeyDidMismatch {
78 expected: crate::dht::Did,
80 actual: crate::dht::Did,
82 },
83
84 #[error("Secp256r1/ECDSA Error: {0}")]
86 ECDSAError(#[from] ecdsa::Error),
87
88 #[error("ECDSA or EdDSA pubkey bad format")]
90 PublicKeyBadFormat,
91
92 #[error("Failed to decode vector to bls affine")]
94 BlsAffineDecodeFailed,
95
96 #[error("private bad format")]
98 PrivateKeyBadFormat,
99
100 #[error("Invalid Transport")]
102 InvalidTransport,
103
104 #[error("InvalidPublicKey")]
106 InvalidPublicKey,
107
108 #[error("Entry kind not equal when overwriting")]
110 EntryKindNotEqual,
111
112 #[error("Did of Entry not equal")]
114 EntryDidNotEqual,
115
116 #[error("The type of Entry is not allowed to be overwritten")]
118 EntryNotOverwritable,
119
120 #[error("The type of Entry is not allowed to be appended")]
122 EntryNotAppendable,
123
124 #[error("Entry dot index {index} is out of bounds")]
126 EntryDotIndexOutOfBounds {
127 index: usize,
129 },
130
131 #[error("Affine rotation scalar must be greater than zero")]
133 InvalidAffineScalar,
134
135 #[error("Storage redundancy mismatch: transport configured {configured}, storage request uses {requested}")]
137 StorageRedundancyMismatch {
138 configured: u16,
140 requested: u16,
142 },
143
144 #[error("Encode a byte vector into a base58-check string, adds 4 bytes checksum")]
146 Encode,
147
148 #[error("Decode base58-encoded with 4 bytes checksum string into a byte vector")]
150 Decode,
151
152 #[error("Couldn't decode data as UTF-8.")]
154 Utf8Encoding(#[from] std::string::FromUtf8Error),
155
156 #[error("IOError")]
158 ServiceIOError(#[from] std::io::Error),
159
160 #[error("Invalid hexadecimal id in directory cache")]
162 BadHexInCache(#[from] hex::FromHexError),
163
164 #[error("Invalid rustc hexadecimal id in directory cache")]
166 BadCHexInCache,
167
168 #[error("URL parse error")]
170 URLParse(#[from] url::ParseError),
171
172 #[error("Invalid hexadecimal id in directory cache")]
174 BadArrayInCache(#[from] std::array::TryFromSliceError),
175
176 #[error("JSON serialize toString error")]
178 SerializeToString,
179
180 #[error("Serialization error")]
182 SerializeError,
183
184 #[error("JSON serialization error")]
186 Serialize(#[source] serde_json::Error),
187
188 #[error("JSON deserialization error")]
190 Deserialize(#[source] serde_json::Error),
191
192 #[error("Codec serialization error")]
194 CodecSerialize(#[source] rings_codec::Error),
195
196 #[error("Codec deserialization error")]
198 CodecDeserialize(#[source] rings_codec::Error),
199
200 #[error("Unknown account")]
202 UnknownAccount,
203
204 #[error("Failed on verify message signature")]
206 VerifySignatureFailed,
207
208 #[error("ECDSA Invalid recover Id {0}")]
210 InvalidRecoverId(u8),
211
212 #[error("Gzip encode error.")]
214 GzipEncode,
215
216 #[error("Gzip decode error.")]
218 GzipDecode,
219
220 #[error("Failed on promise, state is not succeeded")]
222 PromiseStateFailed,
223
224 #[error("promise timeout, state is not succeeded")]
226 PromiseStateTimeout,
227
228 #[error("Ice server scheme {0} has not supported yet")]
230 IceServerSchemeNotSupport(String),
231
232 #[error("Ice server get url without host")]
234 IceServerURLMissHost,
235
236 #[error("Cannot find next node by local DHT")]
238 MessageHandlerMissNextNode,
239
240 #[error("Found existing transport when answer offer from remote node")]
242 AlreadyConnected,
243
244 #[error("Pending WebRTC connection capacity {capacity} is exhausted")]
246 PendingConnectionCapacityExceeded {
247 capacity: usize,
249 },
250
251 #[error("Pending WebRTC connection generation is exhausted")]
253 PendingConnectionGenerationExhausted,
254
255 #[error("Connection attempt {generation} for {peer} was superseded")]
257 ConnectionAttemptSuperseded {
258 peer: crate::dht::Did,
260 generation: u64,
262 },
263
264 #[error("Notify predecessor DID {claimed} does not match relay origin {origin}")]
266 NotifyPredecessorOriginMismatch {
267 claimed: crate::dht::Did,
269 origin: crate::dht::Did,
271 },
272
273 #[error("Notify predecessor origin {origin} is not an admitted connection")]
275 NotifyPredecessorOriginNotAdmitted {
276 origin: crate::dht::Did,
278 },
279
280 #[error("Failed to access the swarm connection lifecycle state")]
282 SwarmConnectionLifecycleLock,
283
284 #[error("You should not connect to yourself")]
286 ShouldNotConnectSelf,
287
288 #[error("Send message through channel failed")]
290 ChannelSendMessageFailed,
291
292 #[error("Outbound transfer capacity {capacity} exceeded for peer {peer}")]
294 OutboundTransferCapacityExceeded {
295 peer: crate::dht::Did,
297 capacity: usize,
299 },
300
301 #[error(
303 "Outbound transfer of {requested_bytes} bytes exceeds the remaining {capacity_bytes}-byte budget for peer {peer}"
304 )]
305 OutboundTransferMemoryCapacityExceeded {
306 peer: crate::dht::Did,
308 requested_bytes: usize,
310 capacity_bytes: usize,
312 },
313
314 #[error(
316 "Timed out after {timeout_ms}ms waiting for outbound transfer capacity for peer {peer}"
317 )]
318 OutboundTransferAdmissionTimeout {
319 peer: crate::dht::Did,
321 timeout_ms: u128,
323 },
324
325 #[error("Timed out after {timeout_ms}ms waiting to admit the first outbound frame for {peer}")]
327 OutboundFirstFrameAdmissionTimeout {
328 peer: crate::dht::Did,
330 timeout_ms: u128,
332 },
333
334 #[error(
336 "Detached payload cleanup for {peer} exceeded its {timeout_ms}ms grace after the first-frame deadline"
337 )]
338 DetachedPayloadCleanupTimeout {
339 peer: crate::dht::Did,
341 timeout_ms: u128,
343 },
344
345 #[error("Outbound scheduler requires an active Tokio runtime")]
347 OutboundSchedulerRuntimeUnavailable,
348
349 #[error("Cancelled detached outbound admission published success")]
351 CancelledDetachedAdmissionPublishedSuccess,
352
353 #[error("Inbound mailbox capacity {capacity} exceeded")]
355 InboundMailboxCapacityExceeded {
356 capacity: usize,
358 },
359
360 #[error(
362 "Inbound message of {requested_bytes} bytes exceeds the {capacity_bytes}-byte mailbox budget"
363 )]
364 InboundMailboxMemoryCapacityExceeded {
365 requested_bytes: usize,
367 capacity_bytes: usize,
369 },
370
371 #[error("Inbound peer {peer:?} capacity {capacity} exceeded")]
373 InboundPeerCapacityExceeded {
374 peer: Option<crate::dht::Did>,
376 capacity: usize,
378 },
379
380 #[error(
382 "Inbound peer {peer:?} message of {requested_bytes} bytes exceeds its {capacity_bytes}-byte budget"
383 )]
384 InboundPeerMemoryCapacityExceeded {
385 peer: Option<crate::dht::Did>,
387 requested_bytes: usize,
389 capacity_bytes: usize,
391 },
392
393 #[error("Inbound mailbox is closed")]
395 InboundMailboxClosed,
396
397 #[error("Inbound mailbox requires an active Tokio runtime")]
399 InboundMailboxRuntimeUnavailable,
400
401 #[error("Inbound actor state invariant violated")]
403 InboundActorInvariantViolation,
404
405 #[error("Nested chunk messages are not allowed")]
407 NestedChunkMessage,
408
409 #[error("Invalid chunk message")]
411 InvalidChunkMessage,
412
413 #[error("Inbound message validation failed: {source}")]
415 InboundValidationFailed {
416 #[source]
418 source: CallbackError,
419 },
420
421 #[error("Inbound validation for {peer:?} timed out after {timeout_ms}ms")]
423 InboundValidationTimeout {
424 peer: Option<crate::dht::Did>,
426 timeout_ms: u128,
428 },
429
430 #[error("Inbound message callback failed: {source}")]
432 InboundCallbackFailed {
433 #[source]
435 source: CallbackError,
436 },
437
438 #[error("Inbound processing for {peer:?} timed out after {timeout_ms}ms")]
440 InboundProcessingTimeout {
441 peer: Option<crate::dht::Did>,
443 timeout_ms: u128,
445 },
446
447 #[error("Inbound {operation} timer unavailable for {peer:?}")]
449 InboundTimerUnavailable {
450 peer: Option<crate::dht::Did>,
452 operation: &'static str,
454 },
455
456 #[error("Recv message through channel failed {0}")]
458 ChannelRecvMessageFailed(String),
459
460 #[error("Invalid PeerRingAction")]
462 PeerRingInvalidAction,
463
464 #[error("Failed on read successors")]
466 FailedToReadSuccessors,
467
468 #[error("Successor index {index} is out of bounds for length {len}")]
470 SuccessorIndexOutOfBounds {
471 index: usize,
473 len: usize,
475 },
476
477 #[error("Failed on write successors")]
479 FailedToWriteSuccessors,
480
481 #[error("Failed on TryInto Entry")]
483 PeerRingInvalidEntry,
484
485 #[error("Unexpected PeerRingAction, {0:?}")]
487 PeerRingUnexpectedAction(Box<crate::dht::PeerRingAction>),
488
489 #[error("PeerRing findsuccessor error, {0}")]
491 PeerRingFindSuccessor(String),
492
493 #[error("PeerRing cannot find closest preceding node")]
495 PeerRingNotFindClosestNode,
496
497 #[error("PeerRing RWLock unlock failed")]
499 PeerRingUnlockFailed,
500
501 #[error("Cannot seek did in swarm table, {0}")]
503 SwarmMissDidInTable(crate::dht::Did),
504
505 #[error("Cannot gather local candidate, {0}")]
507 FailedOnGatherLocalCandidate(String),
508
509 #[error("Node behaviour bad")]
511 NodeBehaviourBad(crate::dht::Did),
512
513 #[error("Cannot get transport from did: {0}")]
515 SwarmMissTransport(crate::dht::Did),
516
517 #[error("Load message failed with message: {0}")]
519 SwarmLoadMessageRecvFailed(String),
520
521 #[error("Default transport is not connected")]
523 SwarmDefaultTransportNotConnected,
524
525 #[error("call lock() failed")]
527 SwarmPendingTransTryLockFailed,
528
529 #[error("transport not found")]
531 SwarmPendingTransNotFound,
532
533 #[error("failed to close previous when registering, {0}")]
535 SwarmToClosePrevTransport(String),
536
537 #[error("call lock() failed")]
539 SessionTryLockFailed,
540
541 #[error("Invalid peer type")]
543 InvalidPeerType,
544
545 #[cfg(not(all(feature = "wasm", target_family = "wasm")))]
546 #[error("RTC new peer connection failed")]
548 RTCPeerConnectionCreateFailed(#[source] webrtc::Error),
549
550 #[error("RTC peer_connection not establish")]
552 RTCPeerConnectionNotEstablish,
553
554 #[cfg(not(all(feature = "wasm", target_family = "wasm")))]
555 #[error("RTC peer_connection fail to create offer")]
557 RTCPeerConnectionCreateOfferFailed(#[source] webrtc::Error),
558
559 #[cfg(all(feature = "wasm", target_family = "wasm"))]
560 #[error("RTC peer_connection fail to create offer")]
562 RTCPeerConnectionCreateOfferFailed(String),
563
564 #[cfg(not(all(feature = "wasm", target_family = "wasm")))]
565 #[error("RTC peer_connection fail to create answer")]
567 RTCPeerConnectionCreateAnswerFailed(#[source] webrtc::Error),
568
569 #[cfg(all(feature = "wasm", target_family = "wasm"))]
570 #[error("RTC peer_connection fail to create answer")]
572 RTCPeerConnectionCreateAnswerFailed(String),
573
574 #[error("DataChannel message size not match, {0} < {1}")]
576 RTCDataChannelMessageIncomplete(usize, usize),
577
578 #[cfg(not(all(feature = "wasm", target_family = "wasm")))]
579 #[error("DataChannel send text message failed")]
581 RTCDataChannelSendTextFailed(#[source] webrtc::Error),
582
583 #[cfg(all(feature = "wasm", target_family = "wasm"))]
584 #[error("DataChannel send text message failed, {0}")]
586 RTCDataChannelSendTextFailed(String),
587
588 #[error("DataChannel not ready")]
590 RTCDataChannelNotReady,
591
592 #[error("DataChannel state not open")]
594 RTCDataChannelStateNotOpen,
595
596 #[error("Transport not ready: state {state:?}, data channel open: {data_channel_open}")]
598 TransportNotReady {
599 state: rings_transport::core::transport::WebrtcConnectionState,
601 data_channel_open: bool,
603 },
604
605 #[cfg(not(all(feature = "wasm", target_family = "wasm")))]
606 #[error("RTC peer_connection add ice candidate error")]
608 RTCPeerConnectionAddIceCandidateError(#[source] webrtc::Error),
609
610 #[cfg(all(feature = "wasm", target_family = "wasm"))]
611 #[error("RTC peer_connection add ice candidate error")]
613 RTCPeerConnectionAddIceCandidateError(String),
614
615 #[cfg(not(all(feature = "wasm", target_family = "wasm")))]
616 #[error("RTC peer_connection set local description failed")]
618 RTCPeerConnectionSetLocalDescFailed(#[source] webrtc::Error),
619
620 #[cfg(all(feature = "wasm", target_family = "wasm"))]
621 #[error("RTC peer_connection set local description failed")]
623 RTCPeerConnectionSetLocalDescFailed(String),
624
625 #[cfg(not(all(feature = "wasm", target_family = "wasm")))]
626 #[error("RTC peer_connection set remote description failed")]
628 RTCPeerConnectionSetRemoteDescFailed(#[source] webrtc::Error),
629
630 #[cfg(all(feature = "wasm", target_family = "wasm"))]
631 #[error("RTC peer_connection set remote description failed")]
633 RTCPeerConnectionSetRemoteDescFailed(String),
634
635 #[cfg(not(all(feature = "wasm", target_family = "wasm")))]
636 #[error("RTC peer_connection failed to close it")]
638 RTCPeerConnectionCloseFailed(#[source] webrtc::Error),
639
640 #[error("RTC unsupported sdp type")]
642 RTCSdpTypeNotMatch,
643
644 #[error("Connection not Found")]
646 ConnectionNotFound,
647
648 #[error("Invalid Transport Id")]
650 InvalidTransportUuid,
651
652 #[error("Unexpected encrypted data")]
654 UnexpectedEncryptedData,
655
656 #[error("Failed to decrypt data")]
658 DecryptionError,
659
660 #[error("Current node is not the next hop of message")]
662 InvalidNextHop,
663
664 #[error("Adjacent elements in path cannot be equal")]
666 InvalidRelayPath,
667
668 #[error("Suspected infinite looping in path")]
670 InfiniteRelayPath,
671
672 #[error("The destination of report message should always be the first element of path")]
674 InvalidRelayDestination,
675
676 #[error("Cannot infer next hop")]
678 CannotInferNextHop,
679
680 #[error("Cannot get next hop when sending message")]
682 NoNextHop,
683
684 #[error("To generate REPORT, you should provide SEND")]
686 ReportNeedSend,
687
688 #[error("Only SEND message can reset destination")]
690 ResetDestinationNeedSend,
691
692 #[cfg(all(feature = "wasm", target_family = "wasm"))]
693 #[error("IndexedDB error, {0}")]
695 IDBError(rexie::Error),
696
697 #[error("Invalid capacity value")]
699 InvalidCapacity,
700
701 #[error("entry not found")]
703 EntryNotFound,
704
705 #[error("IO error: {0}")]
707 IOError(std::io::Error),
708
709 #[error("Failed to get dht from a sync lock")]
711 DHTSyncLockError,
712
713 #[error("Failed to lock callback of swarm")]
715 CallbackSyncLockError,
716
717 #[error("Failed to build swarm: {0}")]
719 SwarmBuildFailed(String),
720
721 #[error("Message invalid: {0}")]
723 InvalidMessage(String),
724
725 #[error("Message encryption failed")]
727 MessageEncryptionFailed(String),
728
729 #[error("Message decryption failed")]
731 MessageDecryptionFailed(String),
732
733 #[error("Message has {0} bytes which is too large")]
735 MessageTooLarge(usize),
736
737 #[error("Serialized message size exceeds the local platform limit")]
739 MessageSizeOverflow,
740
741 #[error("Peer's negotiated max_message_size {0} is too small to carry even one chunk")]
743 PeerMaxMessageSizeTooSmall(usize),
744
745 #[error(
747 "Timed out after {timeout_ms}ms waiting for data-channel send queue to accept {bytes} bytes for {peer} during {context}"
748 )]
749 DataChannelSendQueueTimeout {
750 peer: crate::dht::Did,
752 timeout_ms: u128,
754 bytes: usize,
756 context: &'static str,
758 },
759 #[error(
761 "Timed out after {timeout_ms}ms completing an irrevocable {bytes}-byte data-channel send to {peer} during {context}"
762 )]
763 DataChannelSendCompletionTimeout {
764 peer: crate::dht::Did,
766 timeout_ms: u128,
768 bytes: usize,
770 context: &'static str,
772 },
773
774 #[error(
776 "Timed out after {timeout_ms}ms waiting for data-channel delivery to {peer} during {context}"
777 )]
778 DataChannelDeliveryTimeout {
779 peer: crate::dht::Did,
781 timeout_ms: u128,
783 context: &'static str,
785 },
786
787 #[error(
789 "Tracked payload cleanup for {peer} exceeded its {timeout_ms}ms grace after the send deadline"
790 )]
791 TrackedPayloadCleanupTimeout {
792 peer: crate::dht::Did,
794 timeout_ms: u128,
796 },
797
798 #[cfg(all(feature = "wasm", target_family = "wasm"))]
799 #[error("Cannot get property {0} from JsValue")]
801 FailedOnGetProperty(String),
802
803 #[cfg(all(feature = "wasm", target_family = "wasm"))]
804 #[error("Cannot set property {0} from JsValue")]
806 FailedOnSetProperty(String),
807
808 #[cfg(all(feature = "wasm", target_family = "wasm"))]
809 #[error("Error on ser/der JsValue")]
811 SerdeWasmBindgenError(#[from] serde_wasm_bindgen::Error),
812
813 #[cfg(all(feature = "wasm", target_family = "wasm"))]
814 #[error("Error create RTC connection: {0}")]
816 CreateConnectionError(String),
817
818 #[error("Session is expired")]
820 SessionExpired,
821
822 #[error("Transport error: {0}")]
824 Transport(#[from] rings_transport::error::Error),
825
826 #[error("External Javascript error: {0}")]
828 JsError(String),
829}