Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions cmd/topicctl/subcmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"
"unicode"

"github.com/segmentio/topicctl/pkg/admin"
"github.com/segmentio/topicctl/pkg/apply"
Expand Down Expand Up @@ -215,6 +217,16 @@ func applyRun(cmd *cobra.Command, args []string) error {
}

// prints changes as JSON to stdout
// sanitizeErrorString replaces all non-printable characters with spaces
func sanitizeErrorString(s string) string {
return strings.Map(func(r rune) rune {
if unicode.IsPrint(r) {
return r
}
return ' '
}, s)
}

func printJson(changes apply.NewOrUpdatedChanges) (map[string]interface{}, error) {
jsonChanges, err := json.Marshal(changes)
if err != nil {
Expand Down Expand Up @@ -320,11 +332,16 @@ func applyTopic(
// Some topic creation errors also still create the topic
log.Error("Error detected while creating or updating a topic")
log.Error("The following changes were still made:")
partialChanges, printErr := printJson(topicChanges)
if printErr != nil {
log.Error("Error printing JSON changes data")

if topicChanges == nil {
fmt.Printf("{\"error\": \"%s\"}\n", sanitizeErrorString(err.Error()))
} else {
log.Errorf("%#v", partialChanges)
partialChanges, printErr := printJson(topicChanges)
if printErr != nil {
log.Error("Error printing JSON changes data")
} else {
log.Errorf("%#v", partialChanges)
}
}
return err
}
Expand Down
16 changes: 15 additions & 1 deletion py/parse_and_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,21 @@ def main():
)

for line in sys.stdin:
topic = json.loads(line)
try:
topic = json.loads(line)
except json.JSONDecodeError as e:
title = f"Topicctl failed to apply in region {SENTRY_REGION}"
Copy link
Member

Choose a reason for hiding this comment

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

can you add the line here? the problem to me is that we don't know the error that comes from topicctl. see #31

Copy link
Author

Choose a reason for hiding this comment

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

Added the whole exception repr in the payload.

Copy link
Author

Choose a reason for hiding this comment

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

By the way. I know the issue. The payload was None because the error was that the config was not consistent

Copy link
Member

Choose a reason for hiding this comment

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

By the way. I know the issue. The payload was None because the error was that the config was not consistent

yeah you do but i still have no idea where to look for topicctl errors, so I think it would be best if the parse_and_notify script just posted all diagnostic info to slack or some other high-vis channel

slack_notifier.send(
title=title, body=f"Topicctl produced invalid JSON: {e}"
)
raise

if "error" in topic:
title = f"Topicctl failed to apply in region {SENTRY_REGION}"
slack_notifier.send(title=title, body=topic["error"])
print(f"Error: {topic['error']}", file=sys.stderr)
exit(-1)

action = topic["action"]
topic_content = (
NewTopic.build(topic)
Expand Down
Loading