-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This introduces a set of known errors, and a command to print those (show errors). Those are to be used by the next commit. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
- Loading branch information
Showing
4 changed files
with
110 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import "errors" | ||
|
||
//go:generate go run gen_errors_map.go -out errors_map.go | ||
|
||
// Well-known errors returned by scan. | ||
var ( | ||
ErrGoInvalidTag = errors.New("go binary has invalid build tag(s) set") | ||
ErrGoMissingSymbols = errors.New("go binary does not contain required symbol(s)") | ||
ErrGoMissingTag = errors.New("go binary does not contain required tag(s)") | ||
ErrMultipleLibcrypto = errors.New("openssl: found multiple different libcrypto versions") | ||
ErrNoCgoInit = errors.New("x_cgo_init not found") | ||
ErrNoLibcrypto = errors.New("openssl: did not find libcrypto library within binary") | ||
ErrNoLibcryptoSO = errors.New("could not find dependent openssl version within container image") | ||
ErrNotCgoEnabled = errors.New("go binary is not CGO_ENABLED") | ||
ErrNotDynLinked = errors.New("executable is not dynamically linked") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//go:build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"flag" | ||
"log" | ||
"os" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
var ( | ||
inFile = flag.String("in", "errors.go", "Input file name") | ||
outFile = flag.String("out", "", "Output file name") | ||
|
||
tmpl = template.Must(template.New("").Parse(`// Generated by go generate; DO NOT EDIT. | ||
package main | ||
var KnownErrors = map[string]error { | ||
{{- range .Vars }} | ||
{{ printf "\"%s\": %s," . . }} | ||
{{- end }} | ||
} | ||
`)) | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
input, err := os.Open(*inFile) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer input.Close() | ||
|
||
out := os.Stdout | ||
if *outFile != "" { | ||
out, err = os.Create(*outFile) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer out.Close() | ||
} | ||
|
||
vars := []string{} | ||
s := bufio.NewScanner(input) | ||
for s.Scan() { | ||
line := s.Text() | ||
if strings.HasPrefix(line, "\tErr") { | ||
// Extract the variable name. | ||
vars = append(vars, line[1:strings.IndexByte(line, ' ')]) | ||
} | ||
} | ||
if err := s.Err(); err != nil { | ||
log.Fatal(err) | ||
} | ||
tmpl.Execute(out, struct { | ||
Vars []string | ||
}{ | ||
Vars: vars, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters