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)
| 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. |
| 11 | func 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 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…