mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-22 13:29:01 +08:00
cmd: Avoid panic when printing version without build info (#5210)
* version: don't panic if read build info doesn't work If `debug.ReadBuildInfo()` doesn't return the build information we should not try to access it. Especially if users only want to build with the `CustomVersion` we should not assume access to `debug.ReadBuildInfo()`. The build environment where this isn't available for me is when building with bazel. * exit early
This commit is contained in:
parent
4fe5e64e46
commit
c3b5b1811c
12
caddy.go
12
caddy.go
|
@ -864,7 +864,16 @@ func Version() (simple, full string) {
|
|||
// bi.Main... hopefully.
|
||||
var module *debug.Module
|
||||
bi, ok := debug.ReadBuildInfo()
|
||||
if ok {
|
||||
if !ok {
|
||||
if CustomVersion != "" {
|
||||
full = CustomVersion
|
||||
simple = CustomVersion
|
||||
return
|
||||
}
|
||||
full = "unknown"
|
||||
simple = "unknown"
|
||||
return
|
||||
}
|
||||
// find the Caddy module in the dependency list
|
||||
for _, dep := range bi.Deps {
|
||||
if dep.Path == ImportPath {
|
||||
|
@ -872,7 +881,6 @@ func Version() (simple, full string) {
|
|||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if module != nil {
|
||||
simple, full = module.Version, module.Version
|
||||
if module.Sum != "" {
|
||||
|
|
Loading…
Reference in New Issue
Block a user