Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: empty result plan. #511

Merged
merged 1 commit into from
Apr 17, 2023
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
8 changes: 7 additions & 1 deletion kclvm/runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ pub fn exec_program(
};
// Exec result is a JSON or YAML string.
let exec_result = match exec_result {
Ok(res) => res,
Ok(res) => {
if res.is_empty() {
return Ok(result);
} else {
res
}
}
Err(res) => {
if res.is_empty() {
return Ok(result);
Expand Down
4 changes: 3 additions & 1 deletion kclvm/runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ impl KclvmRunner {
warn_buffer,
);

if n > 0 {
if n == 0 {
Ok("".to_string())
} else if n > 0 {
let return_len = n;
let s = std::str::from_utf8(&result[0..return_len as usize]).unwrap();
wrap_msg_in_result(s)
Expand Down
2 changes: 2 additions & 0 deletions test/grammar/misc/empty_plan/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# _a is a hidden attribute.
_a = 1
Empty file.