| 1 | package acp |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "unicode/utf8" |
| 6 | |
| 7 | "reasonix/internal/i18n" |
| 8 | "reasonix/internal/provider" |
| 9 | "reasonix/internal/secrets" |
| 10 | ) |
| 11 | |
| 12 | func clipStatusText(value string, limit int) string { |
| 13 | value = strings.TrimSpace(secrets.Redact(value)) |
| 14 | return clipStatusValue(value, limit) |
| 15 | } |
| 16 | |
| 17 | func clipStatusCredentialText(value string, limit int) string { |
| 18 | value = strings.TrimSpace(secrets.RedactCredentials(value)) |
| 19 | return clipStatusValue(value, limit) |
| 20 | } |
| 21 | |
| 22 | func clipStatusValue(value string, limit int) string { |
| 23 | if limit <= 0 { |
| 24 | return "" |
| 25 | } |
| 26 | value = strings.ToValidUTF8(value, "\uFFFD") |
| 27 | if len(value) <= limit { |
| 28 | return value |
| 29 | } |
| 30 | end := limit |
| 31 | for end > 0 && !utf8.RuneStart(value[end]) { |
| 32 | end-- |
| 33 | } |
| 34 | return value[:end] |
| 35 | } |
| 36 | |
| 37 | func clipStatusError(err error, limit int) string { |
| 38 | if err == nil { |
| 39 | return "" |
| 40 | } |
| 41 | if provider.IsOpaqueBadRequest(err) { |
| 42 | return clipStatusCredentialText(i18n.M.ProviderErrReasonMissing, limit) |
| 43 | } |
| 44 | return clipStatusCredentialText(err.Error(), limit) |
| 45 | } |
| 46 |