-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
fix(client/v2): respect output format from client ctx #20033
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,6 +11,8 @@ import ( | |||||||||||||||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" | ||||||||||||||||||
"cosmossdk.io/client/v2/internal/flags" | ||||||||||||||||||
"cosmossdk.io/client/v2/internal/util" | ||||||||||||||||||
|
||||||||||||||||||
"github.com/cosmos/cosmos-sdk/client" | ||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
type cmdType int | ||||||||||||||||||
|
@@ -224,11 +226,15 @@ func enhanceCustomCmd(builder *Builder, cmd *cobra.Command, cmdType cmdType, mod | |||||||||||||||||
|
||||||||||||||||||
// outOrStdoutFormat formats the output based on the output flag and writes it to the command's output stream. | ||||||||||||||||||
func (b *Builder) outOrStdoutFormat(cmd *cobra.Command, out []byte) error { | ||||||||||||||||||
var err error | ||||||||||||||||||
outputType := cmd.Flag(flags.FlagOutput) | ||||||||||||||||||
clientCtx, err := client.GetClientTxContext(cmd) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we directly get the client context from its context key instead of using the helper and if not present fallback to the current logic? We are trying to make client.Context optional in the AutoCLI core logic (I know we are not there yet 😅, but that change would not add extra dependencies) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems still need import client for context and key There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we need to import client context anyway for the type check, but that's okay. It just makes clearer what our deps on client.Context are. |
||||||||||||||||||
if err != nil { | ||||||||||||||||||
return err | ||||||||||||||||||
} | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure proper error handling in - if err != nil {
- return err
- }
+ if err != nil {
+ return fmt.Errorf("failed to get client transaction context: %w", err)
+ } This change enhances the error message, providing more context about where the error occurred, which is helpful for debugging. Committable suggestion
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
outputType := clientCtx.OutputFormat | ||||||||||||||||||
// if the output type is text, convert the json to yaml | ||||||||||||||||||
// if output type is json or nil, default to json | ||||||||||||||||||
if outputType != nil && outputType.Value.String() == flags.OutputFormatText { | ||||||||||||||||||
if outputType == flags.OutputFormatText { | ||||||||||||||||||
tac0turtle marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
out, err = yaml.JSONToYAML(out) | ||||||||||||||||||
if err != nil { | ||||||||||||||||||
return err | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changelog should be under client/v2