Skip to content

Commit

Permalink
Update returns and add changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
ianrumac committed Oct 17, 2024
1 parent 32c0fef commit a635f89
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# CHANGELOG


## 0.1.9

## Enhancements

- Added returning of a JSON encoded `Result<PassableValue,String>` from the exposed methods instead of relying on panics.
Example JSON:
- Error: `{"Err":"No such key: should_display"}`
- Ok: `{"Ok":{"type":"bool","value":true}}`

## Fixes
- Fixed a bug where getting properties from `device` would panic when `device` functions were defined
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn evaluate_ast_with_context(definition: String, host: Arc<dyn HostContext>)
data.computed,
data.device,
host,
).map(|val| val.to_string())
).map(|val| val.to_passable())
.map_err(|err| err.to_string());
serde_json::to_string(&res).unwrap()
}
Expand All @@ -79,7 +79,7 @@ pub fn evaluate_ast(ast: String) -> String {
let data: JSONExpression = serde_json::from_str(ast.as_str()).expect("Invalid definition for AST Execution");
let ctx = Context::default();
let res = ctx.resolve(&data.into())
.map(|val| DisplayableValue(val.clone()).to_string())
.map(|val| DisplayableValue(val.clone()).to_passable())
.map_err(|err| DisplayableError(err).to_string());
serde_json::to_string(&res).unwrap()
}
Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn evaluate_with_context(definition: String, host: Arc<dyn HostContext>) ->
data.computed,
data.device,
host,
).map(|val| val.to_string())
).map(|val| val.to_passable())
.map_err(|err| err.to_string())

}
Expand Down Expand Up @@ -474,7 +474,7 @@ mod tests {
.to_string(),
ctx,
);
assert_eq!(res, "{\"Ok\":\"true\"}");
assert_eq!(res, "{\"Ok\":{\"type\":\"bool\",\"value\":true}}");
}

#[tokio::test]
Expand All @@ -497,7 +497,7 @@ mod tests {
.to_string(),
ctx,
);
assert_eq!(res, "{\"Ok\":\"true\"}");
assert_eq!(res, "{\"Ok\":{\"type\":\"bool\",\"value\":true}}");
}

#[test]
Expand Down Expand Up @@ -550,7 +550,7 @@ mod tests {
.to_string(),
ctx,
);
assert_eq!(res, "{\"Ok\":\"true\"}");
assert_eq!(res, "{\"Ok\":{\"type\":\"bool\",\"value\":true}}");
}

#[tokio::test]
Expand Down Expand Up @@ -586,7 +586,7 @@ mod tests {
ctx,
);
println!("{}", res.clone());
assert_eq!(res, "{\"Ok\":\"true\"}");
assert_eq!(res, "{\"Ok\":{\"type\":\"bool\",\"value\":true}}");
}

#[tokio::test]
Expand Down Expand Up @@ -695,7 +695,7 @@ mod tests {
ctx,
);
println!("{}", res.clone());
assert_eq!(res, "{\"Ok\":\"true\"}");
assert_eq!(res, "{\"Ok\":{\"type\":\"bool\",\"value\":true}}");
}

#[tokio::test]
Expand Down Expand Up @@ -781,7 +781,7 @@ mod tests {
ctx,
);
println!("{}", res.clone());
assert_eq!(res, "{\"Ok\":\"true\"}");
assert_eq!(res, "{\"Ok\":{\"type\":\"bool\",\"value\":true}}");
}


Expand Down

0 comments on commit a635f89

Please sign in to comment.