@@ -7,8 +7,10 @@ import (
77 "os"
88 "os/signal"
99 "path/filepath"
10+ "strings"
1011 "syscall"
1112 "time"
13+ "unicode"
1214
1315 "github.com/segmentio/topicctl/pkg/admin"
1416 "github.com/segmentio/topicctl/pkg/apply"
@@ -215,6 +217,16 @@ func applyRun(cmd *cobra.Command, args []string) error {
215217}
216218
217219// prints changes as JSON to stdout
220+ // sanitizeErrorString replaces all non-printable characters with spaces
221+ func sanitizeErrorString (s string ) string {
222+ return strings .Map (func (r rune ) rune {
223+ if unicode .IsPrint (r ) {
224+ return r
225+ }
226+ return ' '
227+ }, s )
228+ }
229+
218230func printJson (changes apply.NewOrUpdatedChanges ) (map [string ]interface {}, error ) {
219231 jsonChanges , err := json .Marshal (changes )
220232 if err != nil {
@@ -320,11 +332,16 @@ func applyTopic(
320332 // Some topic creation errors also still create the topic
321333 log .Error ("Error detected while creating or updating a topic" )
322334 log .Error ("The following changes were still made:" )
323- partialChanges , printErr := printJson ( topicChanges )
324- if printErr ! = nil {
325- log . Error ( "Error printing JSON changes data" )
335+
336+ if topicChanges = = nil {
337+ fmt . Printf ( "{ \" error \" : \" %s \" } \n " , sanitizeErrorString ( err . Error ()) )
326338 } else {
327- log .Errorf ("%#v" , partialChanges )
339+ partialChanges , printErr := printJson (topicChanges )
340+ if printErr != nil {
341+ log .Error ("Error printing JSON changes data" )
342+ } else {
343+ log .Errorf ("%#v" , partialChanges )
344+ }
328345 }
329346 return err
330347 }
0 commit comments