MCPcopy Index your code
hub / github.com/coder/guts / parsePackageError

Function parsePackageError

errors.go:11–25  ·  view source on GitHub ↗

parsePackageError parses the error returned from the go parser when it fails to parse a package and returns a human-readable error message.

(e error)

Source from the content-addressed store, hash-verified

9// parsePackageError parses the error returned from the go parser when it fails to parse a package
10// and returns a human-readable error message.
11func parsePackageError(e error) string {
12 switch {
13 case strings.Contains(e.Error(), "could not import"):
14 // This error message is because the generator does not have access to some package.
15 // This error message could be improved.
16 parts := regexp.MustCompile(`could not import ([^\s]+)`).FindStringSubmatch(e.Error())
17 if len(parts) >= 2 {
18 return fmt.Sprintf("parsing package, suggest running 'go get %s' where calling the go generator to include the referenced package.", parts[1])
19 }
20 return "parsing package, import unavailable to generating code, try to add the package as a reference to the go generator"
21 default:
22 // Log error as is
23 return "parsing package"
24 }
25}

Callers 1

includeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…