Skip to content

Commit

Permalink
Truncate too long exec log
Browse files Browse the repository at this point in the history
  • Loading branch information
motoki317 committed Dec 13, 2023
1 parent 3452d50 commit e79cd5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,21 @@ func (dc *DeployCommand) Execute(ctx *Context) error {
cmd.Stdout = &buf
cmd.Stderr = &buf

const logLimit = 9900

err := cmd.Run()
if err != nil {
return ctx.ReplyFailure(
fmt.Sprintf("exec failed: %v", err),
"```",
safeConvertString(buf.Bytes()),
limitLog(safeConvertString(buf.Bytes()), logLimit),
"```",
)
}

return ctx.ReplySuccess(
"```",
safeConvertString(buf.Bytes()),
limitLog(safeConvertString(buf.Bytes()), logLimit),
"```",
)
}
Expand Down
7 changes: 7 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ func safeConvertString(b []byte) string {
return bld.String()
}

func limitLog(s string, limit int) string {
if len(s) <= limit {
return s
}
return "(log truncated)\n" + s[len(s)-limit:]
}

func withRetry(ctx context.Context, maxRetryCount int, fn func(ctx context.Context) error) error {
const (
initialBackoff = 1 * time.Second
Expand Down

0 comments on commit e79cd5e

Please sign in to comment.