Skip to content

Print output in json format when using global --json flag - #274

Open
vbmade2000 wants to merge 4 commits into
reductstore:mainfrom
vbmade2000:mvora/254-add-json-output-for-bucket-commands
Open

Print output in json format when using global --json flag#274
vbmade2000 wants to merge 4 commits into
reductstore:mainfrom
vbmade2000:mvora/254-add-json-output-for-bucket-commands

Conversation

@vbmade2000

Copy link
Copy Markdown
Contributor

Closes #254

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • CHANGELOG.md has been updated (for bug fixes / features / docs)

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:

Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
@vbmade2000

Copy link
Copy Markdown
Contributor Author

@atimin The PR is still in WIP. Let me know your thoughts on approach taken in this PR.

Comment thread src/main.rs Outdated
// Do not output json if the command is "cp"
if matches.get_flag("json") && command != "cp" {
let json_error = json!({
"status": "error",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I didn't know that ReductError error has status code too. I'll update the code.

@atimin

atimin commented Jul 22, 2026

Copy link
Copy Markdown
Member

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>
@vbmade2000

vbmade2000 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@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.

@vbmade2000
vbmade2000 requested a review from atimin July 22, 2026 14:37
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
Comment thread src/main.rs
(reduct_err.status() as i32, reduct_err.message().to_string())
} else {
// If not a ReductError, use 1 as unknown status
(1, err.to_string())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No probs. I'll keep that in mind.

@vbmade2000
vbmade2000 marked this pull request as ready for review July 29, 2026 08:35
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
@vbmade2000
vbmade2000 force-pushed the mvora/254-add-json-output-for-bucket-commands branch from 317ad1a to 6d38d33 Compare July 29, 2026 08:56
@vbmade2000

Copy link
Copy Markdown
Contributor Author

@atimin This one is ready for review. I don't know why the test is failing. It passes on my system.

@vbmade2000 vbmade2000 closed this Jul 29, 2026
@vbmade2000 vbmade2000 reopened this Jul 29, 2026
@vbmade2000

Copy link
Copy Markdown
Contributor Author

Closed by mistake.

@atimin atimin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@atimin

atimin commented Jul 31, 2026

Copy link
Copy Markdown
Member

@atimin This one is ready for review. I don't know why the test is failing. It passes on my system.

The "cargo fmt" command is failing. You can use pre-commit to run the formatting automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task: add --json output for bucket commands

2 participants