Truncate too long error response

This commit is contained in:
Zoltán Papp
2025-11-17 14:01:21 +01:00
parent 554c9bcf4b
commit 39bec2dd74

View File

@@ -26,6 +26,11 @@ const (
JobTypeBundle JobType = "bundle"
)
const (
// MaxJobReasonLength is the maximum length allowed for job failure reasons
MaxJobReasonLength = 4096
)
type Job struct {
// ID is the primary identifier
ID string `gorm:"primaryKey"`
@@ -171,7 +176,11 @@ func (j *Job) ApplyResponse(resp *proto.JobResponse) error {
case proto.JobStatus_failed:
j.Status = JobStatusFailed
if len(resp.Reason) > 0 {
j.FailedReason = fmt.Sprintf("Client error: '%s'", resp.Reason)
reason := string(resp.Reason)
if len(resp.Reason) > MaxJobReasonLength {
reason = string(resp.Reason[:MaxJobReasonLength]) + "... (truncated)"
}
j.FailedReason = fmt.Sprintf("Client error: '%s'", reason)
}
return nil
default: