Skip to content

Commit

Permalink
fix(capi): yrx_last_error returning empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Feb 26, 2024
1 parent 0a1c40a commit d75d960
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 7 additions & 5 deletions capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,11 @@ pub unsafe extern "C" fn yrx_buffer_destroy(buf: *mut YRX_BUFFER) {
/// the most recent function was successfully.
#[no_mangle]
pub unsafe extern "C" fn yrx_last_error() -> *const c_char {
if let Some(last_error) = LAST_ERROR.with(|_| None::<CString>) {
last_error.as_ptr()
} else {
std::ptr::null()
}
LAST_ERROR.with_borrow(|last_error| {
if let Some(last_error) = last_error {
last_error.as_ptr()
} else {
std::ptr::null()
}
})
}
11 changes: 9 additions & 2 deletions go/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,18 @@ func TestVariables(t *testing.T) {
assert.Len(t, matchingRules, 1)

err := c.DefineGlobal("var", struct{}{})
assert.Errorf(t, err, "variable `var` has unsupported type: struct{}")
assert.EqualError(t, err, "variable `var` has unsupported type: struct {}")
}

func TestError(t *testing.T) {
c := NewCompiler()
err := c.AddSource("rule test { condition: foo }")
assert.Error(t, err)
assert.EqualError(t, err, `error: unknown identifier `+"`foo`"+`
╭─[line:1:24]
1 │ rule test { condition: foo }
│ ─┬─
│ ╰─── this identifier has not been declared
───╯
`)
}

0 comments on commit d75d960

Please sign in to comment.