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

Function formatMultiError

cli/root.go:1406–1438  ·  view source on GitHub ↗

formatMultiError formats a multi-error. It formats it as a list of errors. Multiple Errors: <# errors encountered>: 1. 2.

(from string, multi []error, opts *formatOpts)

Source from the content-addressed store, hash-verified

1404// 2. <heading error message>
1405// <verbose error message>
1406func formatMultiError(from string, multi []error, opts *formatOpts) string {
1407 var errorStrings []string
1408 for _, err := range multi {
1409 msg, _ := cliHumanFormatError("", err, opts)
1410 errorStrings = append(errorStrings, msg)
1411 }
1412
1413 // Write errors out
1414 var str strings.Builder
1415 var traceMsg string
1416 if from != "" {
1417 traceMsg = fmt.Sprintf("Trace=[%s])", from)
1418 }
1419 _, _ = str.WriteString(pretty.Sprint(headLineStyle(), fmt.Sprintf("%d errors encountered: %s", len(multi), traceMsg)))
1420 for i, errStr := range errorStrings {
1421 // Indent each error
1422 errStr = strings.ReplaceAll(errStr, "\n", "\n"+indent)
1423 // Error now looks like
1424 // | <line>
1425 // | <line>
1426 prefix := fmt.Sprintf("%d. ", i+1)
1427 if len(prefix) < len(indent) {
1428 // Indent the prefix to match the indent
1429 prefix += strings.Repeat(" ", len(indent)-len(prefix))
1430 }
1431 errStr = prefix + errStr
1432 // Now looks like
1433 // |1.<line>
1434 // | <line>
1435 _, _ = str.WriteString("\n" + errStr)
1436 }
1437 return str.String()
1438}
1439
1440// formatRunCommandError are cli command errors. This kind of error is very
1441// broad, as it contains all errors that occur when running a command.

Callers 1

cliHumanFormatErrorFunction · 0.85

Calls 4

cliHumanFormatErrorFunction · 0.85
headLineStyleFunction · 0.85
WriteStringMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected