Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 39 additions & 1 deletion rust_slim/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ impl<R: Read, W: Write> SlimServer<R, W> {
let mut results = Vec::new();
for instruction in instructions {
match instruction {
Instruction::Malformed { id, fields } => {
results.push(InstructionResult::exception(
id,
ExceptionMessage::new(format!(
"MALFORMED_INSTRUCTION [{}]",
fields.join(",")
)),
));
}
Instruction::Import { id, path } => {
self.imports.push(path);
results.push(InstructionResult::ok(id))
Expand Down Expand Up @@ -228,7 +237,7 @@ impl<R: Read, W: Write> SlimServer<R, W> {

#[cfg(test)]
mod tests {
use slim_protocol::Id;
use slim_protocol::{FromSlimReader, Id, ToSlimString};
use std::error::Error;
use std::io::Cursor;

Expand Down Expand Up @@ -476,6 +485,35 @@ mod tests {
Ok(())
}

#[test]
fn malformed_instruction_returns_an_exception_and_keeps_the_batch_running(
) -> Result<(), Box<dyn Error>> {
let mut input = vec![
vec!["bad_id", "unknown", "field"],
vec!["good_id", "import", "TestPath"],
]
.to_slim_string()
.as_bytes()
.to_vec();
input.extend_from_slice("bye".to_slim_string().as_bytes());

let mut output = Vec::new();
SlimServer::new(Cursor::new(input), Cursor::new(&mut output)).run()?;

let mut response = Cursor::new(&output[b"Slim -- V0.5\n".len()..]);
assert_eq!(
vec![
InstructionResult::exception(
Id::from("bad_id"),
ExceptionMessage::new("MALFORMED_INSTRUCTION [bad_id,unknown,field]".into()),
),
InstructionResult::ok(Id::from("good_id")),
],
Vec::<InstructionResult>::from_reader(&mut response)?
);
Ok(())
}

#[test]
fn parse_symbol_with_no_symbol() -> Result<(), Box<dyn Error>> {
let mut vec = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion rust_slim/src/to_slim_result_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl ToSlimResultString for () {
}
}

impl<'a> ToSlimResultString for &'a str {
impl ToSlimResultString for &str {
fn to_slim_result_string(self) -> Result<String, ExecuteMethodError> {
Ok(self.to_string())
}
Expand Down
1 change: 0 additions & 1 deletion slim_protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ description = "General Slim Protocol stuff. Used internally by rust_slim and Tem
[dependencies]
ulid = "1"
thiserror = "1"
read_char = "0.1"
22 changes: 22 additions & 0 deletions slim_protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,24 @@ impl Display for Id {
}
}

/// The recursive value model used by the SliM wire protocol.
///
/// Runtime-only values such as fixture objects are deliberately not represented
/// here; they belong to the execution layer.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum SlimValue {
String(String),
List(Vec<SlimValue>),
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Instruction {
/// An instruction list with an unknown operation or an invalid number of
/// fields. The server must reply to this item and keep processing its batch.
Malformed {
id: Id,
fields: Vec<String>,
},
Import {
id: Id,
path: String,
Expand All @@ -160,12 +176,16 @@ pub enum Instruction {
id: Id,
instance: String,
class: String,
/// Instruction arguments remain string-only until the typed runtime
/// value model is introduced.
args: Vec<String>,
},
Call {
id: Id,
instance: String,
function: String,
/// Instruction arguments remain string-only until the typed runtime
/// value model is introduced.
args: Vec<String>,
},
#[allow(dead_code)]
Expand All @@ -174,6 +194,8 @@ pub enum Instruction {
symbol: String,
instance: String,
function: String,
/// Instruction arguments remain string-only until the typed runtime
/// value model is introduced.
args: Vec<String>,
},
#[allow(dead_code)]
Expand Down
Loading
Loading