Skip to content

Commit 94329c4

Browse files
committed
Moved InvalidKey error into the backpressure module.
1 parent 5c4febb commit 94329c4

File tree

8 files changed

+30
-205
lines changed

8 files changed

+30
-205
lines changed

runtime/swimos_runtime/src/agent/task/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::agent::store::StoreInitError;
2222
use crate::agent::task::links::TriggerUnlink;
2323
use crate::agent::task::sender::LaneSendError;
2424
use crate::agent::task::write_fut::SpecialAction;
25-
use crate::error::InvalidKey;
25+
use crate::backpressure::InvalidKey;
2626
use crate::timeout_coord::{self, VoteResult};
2727

2828
use self::external_links::{LinksTaskState, NoReport};

runtime/swimos_runtime/src/agent/task/remotes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use swimos_utilities::{byte_channel::ByteWriter, trigger::promise};
2020
use tracing::debug;
2121
use uuid::Uuid;
2222

23-
use crate::{agent::DisconnectionReason, error::InvalidKey};
23+
use crate::{agent::DisconnectionReason, backpressure::InvalidKey};
2424
pub use sender::RemoteSender;
2525
pub use uplink::UplinkResponse;
2626

runtime/swimos_runtime/src/agent/task/remotes/uplink/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ use crate::{
2929
},
3030
backpressure::{
3131
recon::MapOperationReconEncoder, BackpressureStrategy, MapBackpressure, SupplyBackpressure,
32-
ValueBackpressure,
32+
ValueBackpressure, InvalidKey
3333
},
34-
error::InvalidKey,
3534
};
3635

3736
#[cfg(test)]

runtime/swimos_runtime/src/backpressure/map_queue/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ use std::{
2020
use bytes::{BufMut, BytesMut};
2121
use swimos_agent_protocol::MapOperation;
2222

23-
use crate::error::InvalidKey;
24-
25-
use super::{key::ReconKey, RawMapOperation, RawMapOperationMut};
23+
use super::{key::ReconKey, RawMapOperation, RawMapOperationMut, InvalidKey};
2624

2725
#[cfg(test)]
2826
mod tests;

runtime/swimos_runtime/src/backpressure/mod.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::{convert::Infallible, fmt::Display};
15+
use std::{convert::Infallible, fmt::{Display, Formatter}};
1616

1717
use bytes::{Buf, BufMut, Bytes, BytesMut};
1818
use swimos_agent_protocol::{DownlinkOperation, MapOperation};
1919
use tokio_util::codec::Encoder;
20+
use std::str::Utf8Error;
21+
use thiserror::Error;
2022

2123
use map_queue::MapOperationQueue;
2224
mod key;
@@ -25,7 +27,6 @@ pub mod recon;
2527

2628
use recon::MapOperationReconEncoder;
2729

28-
use crate::error::InvalidKey;
2930

3031
type RawMapOperation = MapOperation<Bytes, BytesMut>;
3132
type RawMapOperationMut = MapOperation<BytesMut, BytesMut>;
@@ -211,3 +212,26 @@ impl BackpressureStrategy for MapBackpressure {
211212
}
212213
}
213214
}
215+
216+
/// Error indicating that the key for a map message contained invalid UTF8.
217+
#[derive(Debug, Error)]
218+
pub struct InvalidKey {
219+
key_bytes: Bytes,
220+
source: Utf8Error,
221+
}
222+
223+
impl Display for InvalidKey {
224+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
225+
write!(
226+
f,
227+
"The key {:?}, contains invalid UTF8: {}.",
228+
self.key_bytes, self.source
229+
)
230+
}
231+
}
232+
233+
impl InvalidKey {
234+
pub fn new(key_bytes: Bytes, source: Utf8Error) -> Self {
235+
InvalidKey { key_bytes, source }
236+
}
237+
}

runtime/swimos_runtime/src/error/mod.rs

Lines changed: 0 additions & 44 deletions
This file was deleted.

runtime/swimos_runtime/src/error/tls.rs

Lines changed: 0 additions & 151 deletions
This file was deleted.

runtime/swimos_runtime/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@
1515
pub mod agent;
1616
mod backpressure;
1717
pub mod downlink;
18-
pub mod error;
1918
mod timeout_coord;

0 commit comments

Comments
 (0)