Skip to content

Commit

Permalink
Avoid exposing parse error since it affects borrow compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
afsalthaj committed Jun 26, 2024
1 parent ffe1dc2 commit 636a0d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions golem-rib/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ impl Expr {
/// Rib supports conditional calls, function calls, pattern-matching,
/// string interpolation (see error_message above) etc.
///
pub fn from_str(input: &str) -> Result<Expr, easy::ParseError<&str>> {
pub fn from_str(input: &str) -> Result<Expr, String> {
rib_program().easy_parse(input.as_ref()).map(|(expr, _)| expr)
.map_err(|err| err.to_string())
}

/// Parse an interpolated text as Rib expression. The input is always expected to be wrapped with `${..}`
Expand Down Expand Up @@ -117,9 +118,9 @@ impl Expr {
/// if foo > 1 then bar else "baz-${user.id}"
/// ```
///
pub fn from_interpolated_str(input: &str) -> Result<Expr, easy::ParseError<&str>> {
pub fn from_interpolated_str(input: &str) -> Result<Expr, String> {
let input = format!("\"{}\"", input);
rib_program().easy_parse(input.as_ref()).map(|(expr, _)| expr)
Self::from_str(input.as_str())
}
pub fn unsigned_integer(u64: u64) -> Expr {
Expr::Number(Number::Unsigned(u64))
Expand Down
2 changes: 1 addition & 1 deletion golem-rib/src/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod writer;
use crate::text::writer::WriterError;
use combine::stream::easy;

pub fn from_string(input: &str) -> Result<Expr, easy::ParseError<&str>> {
pub fn from_string(input: &str) -> Result<Expr, String> {
Expr::from_str(input.as_ref())
}

Expand Down

0 comments on commit 636a0d7

Please sign in to comment.