MCPcopy Index your code
hub / github.com/coder/coder / truncateFailureRecord

Function truncateFailureRecord

scripts/gotestsummary/main.go:411–441  ·  view source on GitHub ↗
(item failure, capBytes int)

Source from the content-addressed store, hash-verified

409}
410
411func truncateFailureRecord(item failure, capBytes int) ([]byte, bool, error) {
412 if capBytes <= 0 {
413 return nil, false, nil
414 }
415 output := []byte(item.Output)
416 low, high := 0, len(output)
417 var best []byte
418 for low <= high {
419 mid := low + (high-low)/2
420 recordLine, err := marshalRecord(failureRecord{
421 Package: item.Package,
422 Test: item.Test,
423 ElapsedS: item.Elapsed,
424 Output: strings.ToValidUTF8(string(output[:mid]), ""),
425 OutputTruncated: true,
426 })
427 if err != nil {
428 return nil, false, err
429 }
430 if len(recordLine) <= capBytes {
431 best = slices.Clone(recordLine)
432 low = mid + 1
433 continue
434 }
435 high = mid - 1
436 }
437 if best == nil {
438 return nil, false, nil
439 }
440 return best, true, nil
441}
442
443func marshalRecord(record any) ([]byte, error) {
444 line, err := json.Marshal(record)

Callers 1

writeFailuresNDJSONFunction · 0.85

Calls 2

marshalRecordFunction · 0.85
CloneMethod · 0.45

Tested by

no test coverage detected