Print output in json format when using global --json flag - #274
Print output in json format when using global --json flag#274vbmade2000 wants to merge 4 commits into
Conversation
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
|
@atimin The PR is still in WIP. Let me know your thoughts on approach taken in this PR. |
| // Do not output json if the command is "cp" | ||
| if matches.get_flag("json") && command != "cp" { | ||
| let json_error = json!({ | ||
| "status": "error", |
There was a problem hiding this comment.
reduct-rs sdk returns the ReductError with a status and an error message. I think we can attach it to the anyhow error and downcast here to get the status. See https://docs.rs/anyhow/latest/anyhow/trait.Context.html.
There was a problem hiding this comment.
Ah I didn't know that ReductError error has status code too. I'll update the code.
|
Hi @vbmade2000 , I think it's a good approach but we could try to improve the error handling without breaking the interfaces. |
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
|
@atimin I have updated code to return status code. Let me know if it looks good to you. I'll write tests for bucket once you approve the approach. |
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
| (reduct_err.status() as i32, reduct_err.message().to_string()) | ||
| } else { | ||
| // If not a ReductError, use 1 as unknown status | ||
| (1, err.to_string()) |
There was a problem hiding this comment.
Hi @vbmade2000 , sorry looks like I missed your request. Yes, we can continue with the following approach but it should be -1 to be compatible with ReductStore error codes: https://github.com/reductstore/reductstore/blob/661918503a8d762f599ad1a7589c23330fb6c464/reduct_base/src/error.rs#L23
There was a problem hiding this comment.
No probs. I'll keep that in mind.
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
317ad1a to
6d38d33
Compare
|
@atimin This one is ready for review. I don't know why the test is failing. It passes on my system. |
|
Closed by mistake. |
atimin
left a comment
There was a problem hiding this comment.
Hi @vbmade2000 ,
Let's add the flag into all the bucket commands not only "create". Please update the changelog file and the PR description.
Thank you!
The "cargo fmt" command is failing. You can use pre-commit to run the formatting automatically. |
Closes #254
Please check if the PR fulfills these requirements
What kind of change does this PR introduce?
(Bug fix, feature, docs update, ...)
What was changed?
(Describe the changes)
Related issues
(Add links to related issues)
Does this PR introduce a breaking change?
(What changes might users need to make in their application due to this PR?)
Other information: