Skip to content

Commit

Permalink
fixes 152: Force 'migrations inspect' command to output to stdout
Browse files Browse the repository at this point in the history
In the last couple of days the migrations test have failed locally for
no apparent reason, since no code related to them has changed, the
dependency versions have not changed and neither have the migrations
themselves. After a little bit of digging it looks like something in the
ubuntu container is causing the 'OutOrStderr' function call in the
migrations inspect command to return the stderr instead of stdout which
in turn causes the jq check in the migrations bash script to get an
empty input instead of the JSON doc which in turn causes it to fail
immediately. Changing the 'OutOrStderr' to 'OutOrStdout' ensures that
the code will always output to stdout as expected or whatever is the out
stream.
  • Loading branch information
Pavlos Tzianos committed Apr 30, 2024
1 parent c288d4b commit 2cebdcf
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cmd/draconctl/migrations/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,20 @@ func inspectMigrations(cmd *cobra.Command, args []string) error {
Dirty bool
}{latestMigration, isDirty}

marshaledBytes, err := json.Marshal(jsonOutput)
var marshaledBytes []byte
marshaledBytes, err = json.Marshal(jsonOutput)
if err != nil {
return fmt.Errorf("could not marshal JSON output: %w", err)
}
fmt.Fprintln(cmd.OutOrStderr(), string(marshaledBytes))

_, err = fmt.Fprintln(cmd.OutOrStdout(), string(marshaledBytes))
} else {
table := tablewriter.NewWriter(os.Stdout) //cmd.OutOrStdout())
table := tablewriter.NewWriter(cmd.OutOrStdout())
table.SetHeader([]string{"", ""})
table.Append([]string{"Latest Migration Version", fmt.Sprintf("%d", latestMigration)})
table.Append([]string{"Has Failed Migrations", fmt.Sprintf("%v", isDirty)})
table.Render()
}

return nil
return err
}

0 comments on commit 2cebdcf

Please sign in to comment.