2024-01-30 17:19:34 +01:00
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
2023-08-26 19:41:00 +02:00
//! Contains all the errors that can be returned by the library.
2023-04-21 16:18:20 +02:00
use custom_error ::custom_error ;
2023-08-29 18:38:26 +02:00
use crate ::types ::WebSocketEvent ;
2023-04-21 16:18:20 +02:00
custom_error! {
2023-09-03 16:55:19 +02:00
#[ derive(PartialEq, Eq, Clone, Hash) ]
2023-07-09 18:38:02 +02:00
pub RegistrationError
Consent = " Consent must be 'true' to register. " ,
2023-04-21 16:18:20 +02:00
}
2023-04-21 18:20:49 +02:00
2023-07-09 18:38:02 +02:00
pub type ChorusResult < T > = std ::result ::Result < T , ChorusError > ;
2023-06-21 14:46:14 +02:00
2023-04-21 18:20:49 +02:00
custom_error! {
2023-09-03 16:55:19 +02:00
#[ derive(Clone, Hash, PartialEq, Eq) ]
2023-07-09 18:38:02 +02:00
pub ChorusError
/// Server did not respond.
2023-04-21 23:20:23 +02:00
NoResponse = " Did not receive a response from the Server. " ,
2023-07-09 18:38:02 +02:00
/// Reqwest returned an Error instead of a Response object.
2024-01-31 22:27:53 +01:00
RequestFailed { url :String , error : String } = " An error occurred while trying to GET from {url}: {error} " ,
2023-07-09 18:38:02 +02:00
/// Response received, however, it was not of the successful responses type. Used when no other, special case applies.
ReceivedErrorCode { error_code : u16 , error : String } = " Received the following error code while requesting from the route: {error_code} " ,
/// Used when there is likely something wrong with the instance, the request was directed to.
CantGetInformation { error :String } = " Something seems to be wrong with the instance. Cannot get information about the instance: {error} " ,
/// The requests form body was malformed/invalid.
InvalidFormBody { error_type : String , error :String } = " The server responded with: {error_type}: {error} " ,
/// The request has not been processed by the server due to a relevant rate limit bucket being exhausted.
2023-05-14 13:12:02 +02:00
RateLimited { bucket :String } = " Ratelimited on Bucket {bucket} " ,
2023-07-09 18:38:02 +02:00
/// The multipart form could not be created.
MultipartCreation { error : String } = " Got an error whilst creating the form: {error} " ,
/// The regular form could not be created.
FormCreation { error : String } = " Got an error whilst creating the form: {error} " ,
/// The token is invalid.
2023-05-14 13:07:46 +02:00
TokenExpired = " Token expired, invalid or not found. " ,
2023-07-09 18:38:02 +02:00
/// No permission
2023-05-14 13:07:46 +02:00
NoPermission = " You do not have the permissions needed to perform this action. " ,
2023-07-09 18:38:02 +02:00
/// Resource not found
2023-06-18 23:01:38 +02:00
NotFound { error : String } = " The provided resource hasn't been found: {error} " ,
2023-07-09 18:38:02 +02:00
/// Used when you, for example, try to change your spacebar account password without providing your old password for verification.
PasswordRequired = " You need to provide your current password to authenticate for this action. " ,
/// Malformed or unexpected response.
InvalidResponse { error : String } = " The response is malformed and cannot be processed. Error: {error} " ,
/// Invalid, insufficient or too many arguments provided.
InvalidArguments { error : String } = " Invalid arguments were provided. Error: {error} "
2023-04-21 18:20:49 +02:00
}
2023-04-27 22:38:57 +02:00
2023-12-03 12:49:07 +01:00
impl From < reqwest ::Error > for ChorusError {
fn from ( value : reqwest ::Error ) -> Self {
ChorusError ::RequestFailed {
url : match value . url ( ) {
Some ( url ) = > url . to_string ( ) ,
None = > " None " . to_string ( ) ,
} ,
error : value . to_string ( ) ,
}
}
}
2023-04-27 22:38:57 +02:00
custom_error! {
#[ derive(PartialEq, Eq) ]
pub ObserverError
2023-07-09 18:38:02 +02:00
AlreadySubscribed = " Each event can only be subscribed to once. "
2023-04-27 22:38:57 +02:00
}
2023-06-08 17:34:52 +02:00
custom_error! {
Primitive voice implementation (feature/voice) (#457)
* Add Webrtc Identify & Ready
* Add more webrtc typings
* Attempt an untested voice gateway implementation
* fmt
* Merge with main
* Same allow as for voice as normal gateway
* Test error observer
* Minor updates
* More derives
* Even more derives
* Small types update
* e
* Minor doc fixes
* Modernise voice gateway
* Add default impl for voicegatewayerror
* Make voice event fields pub
* Event updates via the scientific method
* ??
* Fix bad request in voice gateway init
* Voice gateway updates
* Fix error failing to 'deserialize' properly
* Update voice identify
* Clarify FIXME related to #430
* Update to v7
* Create seperate voice_gateway.rs and voice_udp.rs
* Restructure voice to new module
* fix: deserialization error in speaking bitflags
* feat: kinda janky ip discovery impl
* feat: return ip discovery data + minor update
* feat: packet parsing!
* fix: voice works again
* feat: add voice_media_sink_wants
(comitting uncommited changes to merge)
* chore: rename events/webrtc to events/voice_gateway
* Add UdpHandle
* chore: clippy + other misc updates
* fix: attempt to fix failing wasm build
* chore: yes clippy, that is indeed an unneeded return statement
* feat: add VoiceData struct
* feat: add VoiceData reference to UdpHandler
* feat: decryption?
* chore: formatting
* feat: add ssrc definition (op 12)
* feat: add untested sending & asbtract nonce generation
* feat: Public api! (sorta)
* small updates
* feat: add sequence number
* chore: yes
* feat: merge VoiceHandler into official development
* chore: yes clippy, you are special
* fix: duplicated gateway events
* feat: first try at vgw wasm compat
* fix: blunder
* fix: gateway connect using wrong url
* fix: properly using encrypted data, bad practice for buffer creation
* chore: split voice udp
* feat: udp error handling, create udp/backends
* fix: its the same
* chore: clarify UDP on WASM
* api: split voice gateway and udp features, test for voice gateway in WASM
* feat: new encryption modes, minor code quality
* docs: document voice encryption modes
* chore: unused imports
* chore: update getrandom version to match wasm version
* chore: update on packet size FIXME
* drop buf asap
* Okay can't do that actually
* tests: add nonce test
* normal tests work?
* docs: fix doc warning, fix incorrect refrences to 'webrtc'
* chore: json isn't a doc test
* tests: better gateway auth test
* testing tests
* update voice heartbeat, fix the new test issue
* committed too much
* fix: unused import
* fix: use ip discovery address as string, not as Vec<u8>
* chore: less obnoxious logging
* chore: better unimplemented voice modes handling
* chore: remove unused variable
* chore: use matches macro
* add voice examples, make gateway ones clearer
* rename voice example
* chore: remove unused VoiceHandler
* fix: implement gateway Reconnect and InvalidSession
* Typo
Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
* Fix a bunch of typos
Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
* fix: error handling while loading native certs
* fix: guh
* use be for nonce bytes
* fix: refactor gw and vgw closures
* remove outdated docs
---------
Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
2024-04-16 17:18:21 +02:00
/// For errors we receive from the gateway, see <https://discord-userdoccers.vercel.app/topics/opcodes-and-status-codes#gateway-close-event-codes>;
2023-06-08 17:34:52 +02:00
///
/// Supposed to be sent as numbers, though they are sent as string most of the time?
///
/// Also includes errors when initiating a connection and unexpected opcodes
2023-08-29 18:38:26 +02:00
#[ derive(PartialEq, Eq, Default, Clone) ]
2023-06-08 17:34:52 +02:00
pub GatewayError
// Errors we have received from the gateway
2023-08-29 18:38:26 +02:00
#[ default ]
2023-07-09 18:38:02 +02:00
Unknown = " We're not sure what went wrong. Try reconnecting? " ,
UnknownOpcode = " You sent an invalid Gateway opcode or an invalid payload for an opcode " ,
Decode = " Gateway server couldn't decode payload " ,
NotAuthenticated = " You sent a payload prior to identifying " ,
AuthenticationFailed = " The account token sent with your identify payload is invalid " ,
AlreadyAuthenticated = " You've already identified, no need to reauthenticate " ,
InvalidSequenceNumber = " The sequence number sent when resuming the session was invalid. Reconnect and start a new session " ,
RateLimited = " You are being rate limited! " ,
SessionTimedOut = " Your session timed out. Reconnect and start a new one " ,
InvalidShard = " You sent us an invalid shard when identifying " ,
ShardingRequired = " The session would have handled too many guilds - you are required to shard your connection in order to connect " ,
InvalidAPIVersion = " You sent an invalid Gateway version " ,
InvalidIntents = " You sent an invalid intent " ,
DisallowedIntents = " You sent a disallowed intent. You may have tried to specify an intent that you have not enabled or are not approved for " ,
2023-06-08 17:34:52 +02:00
// Errors when initiating a gateway connection
2023-07-09 18:38:02 +02:00
CannotConnect { error : String } = " Cannot connect due to a tungstenite error: {error} " ,
NonHelloOnInitiate { opcode : u8 } = " Received non hello on initial gateway connection ({opcode}), something is definitely wrong " ,
2023-06-08 17:34:52 +02:00
// Other misc errors
2023-07-09 18:38:02 +02:00
UnexpectedOpcodeReceived { opcode : u8 } = " Received an opcode we weren't expecting to receive: {opcode} " ,
2023-06-08 17:34:52 +02:00
}
2023-08-29 18:38:26 +02:00
impl WebSocketEvent for GatewayError { }
Primitive voice implementation (feature/voice) (#457)
* Add Webrtc Identify & Ready
* Add more webrtc typings
* Attempt an untested voice gateway implementation
* fmt
* Merge with main
* Same allow as for voice as normal gateway
* Test error observer
* Minor updates
* More derives
* Even more derives
* Small types update
* e
* Minor doc fixes
* Modernise voice gateway
* Add default impl for voicegatewayerror
* Make voice event fields pub
* Event updates via the scientific method
* ??
* Fix bad request in voice gateway init
* Voice gateway updates
* Fix error failing to 'deserialize' properly
* Update voice identify
* Clarify FIXME related to #430
* Update to v7
* Create seperate voice_gateway.rs and voice_udp.rs
* Restructure voice to new module
* fix: deserialization error in speaking bitflags
* feat: kinda janky ip discovery impl
* feat: return ip discovery data + minor update
* feat: packet parsing!
* fix: voice works again
* feat: add voice_media_sink_wants
(comitting uncommited changes to merge)
* chore: rename events/webrtc to events/voice_gateway
* Add UdpHandle
* chore: clippy + other misc updates
* fix: attempt to fix failing wasm build
* chore: yes clippy, that is indeed an unneeded return statement
* feat: add VoiceData struct
* feat: add VoiceData reference to UdpHandler
* feat: decryption?
* chore: formatting
* feat: add ssrc definition (op 12)
* feat: add untested sending & asbtract nonce generation
* feat: Public api! (sorta)
* small updates
* feat: add sequence number
* chore: yes
* feat: merge VoiceHandler into official development
* chore: yes clippy, you are special
* fix: duplicated gateway events
* feat: first try at vgw wasm compat
* fix: blunder
* fix: gateway connect using wrong url
* fix: properly using encrypted data, bad practice for buffer creation
* chore: split voice udp
* feat: udp error handling, create udp/backends
* fix: its the same
* chore: clarify UDP on WASM
* api: split voice gateway and udp features, test for voice gateway in WASM
* feat: new encryption modes, minor code quality
* docs: document voice encryption modes
* chore: unused imports
* chore: update getrandom version to match wasm version
* chore: update on packet size FIXME
* drop buf asap
* Okay can't do that actually
* tests: add nonce test
* normal tests work?
* docs: fix doc warning, fix incorrect refrences to 'webrtc'
* chore: json isn't a doc test
* tests: better gateway auth test
* testing tests
* update voice heartbeat, fix the new test issue
* committed too much
* fix: unused import
* fix: use ip discovery address as string, not as Vec<u8>
* chore: less obnoxious logging
* chore: better unimplemented voice modes handling
* chore: remove unused variable
* chore: use matches macro
* add voice examples, make gateway ones clearer
* rename voice example
* chore: remove unused VoiceHandler
* fix: implement gateway Reconnect and InvalidSession
* Typo
Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
* Fix a bunch of typos
Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
* fix: error handling while loading native certs
* fix: guh
* use be for nonce bytes
* fix: refactor gw and vgw closures
* remove outdated docs
---------
Co-authored-by: Flori <39242991+bitfl0wer@users.noreply.github.com>
2024-04-16 17:18:21 +02:00
custom_error! {
/// Voice Gateway errors
///
/// Similar to [GatewayError].
///
/// See <https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice-voice-close-event-codes>;
#[ derive(Clone, Default, PartialEq, Eq) ]
pub VoiceGatewayError
// Errors we receive
#[ default ]
UnknownOpcode = " You sent an invalid opcode " ,
FailedToDecodePayload = " You sent an invalid payload in your identifying to the (Voice) Gateway " ,
NotAuthenticated = " You sent a payload before identifying with the (Voice) Gateway " ,
AuthenticationFailed = " The token you sent in your identify payload is incorrect " ,
AlreadyAuthenticated = " You sent more than one identify payload " ,
SessionNoLongerValid = " Your session is no longer valid " ,
SessionTimeout = " Your session has timed out " ,
ServerNotFound = " We can't find the server you're trying to connect to " ,
UnknownProtocol = " We didn't recognize the protocol you sent " ,
Disconnected = " Channel was deleted, you were kicked, voice server changed, or the main gateway session was dropped. Should not reconnect. " ,
VoiceServerCrashed = " The server crashed, try resuming " ,
UnknownEncryptionMode = " Server failed to decrypt data " ,
// Errors when initiating a gateway connection
CannotConnect { error : String } = " Cannot connect due to a tungstenite error: {error} " ,
NonHelloOnInitiate { opcode : u8 } = " Received non hello on initial gateway connection ({opcode}), something is definitely wrong " ,
// Other misc errors
UnexpectedOpcodeReceived { opcode : u8 } = " Received an opcode we weren't expecting to receive: {opcode} " ,
}
impl WebSocketEvent for VoiceGatewayError { }
custom_error! {
/// Voice UDP errors.
#[ derive(Clone, PartialEq, Eq) ]
pub VoiceUdpError
// General errors
BrokenSocket { error : String } = " Could not write / read from UDP socket: {error} " ,
NoData = " We have not set received the necessary data to perform this operation. " ,
// Encryption errors
EncryptionModeNotImplemented { encryption_mode : String } = " Voice encryption mode {encryption_mode} is not yet implemented. " ,
NoKey = " Tried to encrypt / decrypt rtp data, but no key has been received yet " ,
FailedEncryption = " Tried to encrypt rtp data, but failed. Most likely this is an issue chorus' nonce generation. Please open an issue on the chorus github: https://github.com/polyphony-chat/chorus/issues/new " ,
FailedDecryption = " Tried to decrypt rtp data, but failed. Most likely this is an issue chorus' nonce generation. Please open an issue on the chorus github: https://github.com/polyphony-chat/chorus/issues/new " ,
FailedNonceGeneration { error : String } = " Tried to generate nonce, but failed due to error: {error}. " ,
// Errors when initiating a socket connection
CannotBind { error : String } = " Cannot bind socket due to a UDP error: {error} " ,
CannotConnect { error : String } = " Cannot connect due to a UDP error: {error} " ,
}
impl WebSocketEvent for VoiceUdpError { }