Skip to content

Commit

Permalink
Merge pull request #4 from omnia-network/release/0.3.1
Browse files Browse the repository at this point in the history
release/0.3.1
  • Loading branch information
ilbertt authored Dec 4, 2023
2 parents e0104cf + 4ff0311 commit 404f54a
Show file tree
Hide file tree
Showing 27 changed files with 2,526 additions and 1,765 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ on:
branches:
- main
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review

jobs:
unit-and-integration-tests:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ cargo test --package ic-websocket-cdk --doc

./scripts/build-test-canister.sh

POCKET_IC_BIN="$(pwd)/bin/pocket-ic" RUST_BACKTRACE=1 cargo test --package ic-websocket-cdk --lib -- tests::integration_tests --test-threads 1
POCKET_IC_BIN="$(pwd)/bin/pocket-ic" cargo test --package ic-websocket-cdk --lib -- tests::integration_tests --test-threads 1
2 changes: 1 addition & 1 deletion src/ic-websocket-cdk/service.example.did
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "./ws_types.did";

// define your message type here
type MyMessageType = {
type MyMessageType = record {
some_field : text;
};

Expand Down
109 changes: 109 additions & 0 deletions src/ic-websocket-cdk/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
use std::{error::Error, fmt};

use crate::{ClientKey, ClientPrincipal, GatewayPrincipal};

#[derive(Debug)]
pub(crate) enum WsError<'a> {
AnonymousPrincipalNotAllowed,
ClientKeyAlreadyConnected {
client_key: &'a ClientKey,
},
ClientKeyMessageMismatch {
client_key: &'a ClientKey,
},
ClientKeyNotConnected {
client_key: &'a ClientKey,
},
ClientNotRegisteredToGateway {
client_key: &'a ClientKey,
gateway_principal: &'a GatewayPrincipal,
},
ClientPrincipalNotConnected {
client_principal: &'a ClientPrincipal,
},
DecodeServiceMessageContent {
err: candid::Error,
},
ExpectedIncomingMessageToClientNumNotInitialized {
client_key: &'a ClientKey,
},
GatewayNotRegistered {
gateway_principal: &'a GatewayPrincipal,
},
InvalidServiceMessage,
IncomingSequenceNumberWrong {
expected_sequence_num: u64,
actual_sequence_num: u64,
},
OutgoingMessageToClientNumNotInitialized {
client_key: &'a ClientKey,
},
}

impl WsError<'_> {
pub(crate) fn to_string_result(&self) -> Result<(), String> {
Err(self.to_string())
}
}

impl fmt::Display for WsError<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let msg = match self {
WsError::AnonymousPrincipalNotAllowed => {
"Anonymous principal is not allowed".to_string()
},
WsError::ClientKeyAlreadyConnected { client_key } => {
format!("Client with key {client_key} already has an open connection")
},
WsError::ClientKeyMessageMismatch { client_key } => {
format!(
"Client with principal {} has a different key than the one used in the message",
client_key.client_principal,
)
},
WsError::ClientKeyNotConnected { client_key } => {
format!("Client with key {client_key} doesn't have an open connection")
},
WsError::ClientNotRegisteredToGateway {
client_key,
gateway_principal,
} => {
format!(
"Client with key {client_key} was not registered to gateway {gateway_principal}"
)
},
WsError::ClientPrincipalNotConnected { client_principal } => {
format!("Client with principal {client_principal} doesn't have an open connection")
},
WsError::DecodeServiceMessageContent { err } => {
format!("Error decoding service message content: {err}")
},
WsError::ExpectedIncomingMessageToClientNumNotInitialized { client_key } => {
format!(
"Expected incoming message to client num not initialized for client key {client_key}"
)
},
WsError::GatewayNotRegistered { gateway_principal } => {
format!("Gateway with principal {gateway_principal} is not registered")
},
WsError::InvalidServiceMessage => "Invalid service message".to_string(),
WsError::IncomingSequenceNumberWrong {
expected_sequence_num,
actual_sequence_num,
} => {
format!(
"Expected incoming sequence number {expected_sequence_num} but got {actual_sequence_num}"
)
},
WsError::OutgoingMessageToClientNumNotInitialized { client_key } => {
format!(
"Outgoing message to client num not initialized for client key {client_key}"
)
},
};

write!(f, "{}", msg)
}
}

impl Error for WsError<'_> {}
Loading

0 comments on commit 404f54a

Please sign in to comment.