mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-16 21:56:40 -05: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
1 changed files with 15 additions and 7 deletions
22
caddy.go
22
caddy.go
|
@ -864,13 +864,21 @@ func Version() (simple, full string) {
|
||||||
// bi.Main... hopefully.
|
// bi.Main... hopefully.
|
||||||
var module *debug.Module
|
var module *debug.Module
|
||||||
bi, ok := debug.ReadBuildInfo()
|
bi, ok := debug.ReadBuildInfo()
|
||||||
if ok {
|
if !ok {
|
||||||
// find the Caddy module in the dependency list
|
if CustomVersion != "" {
|
||||||
for _, dep := range bi.Deps {
|
full = CustomVersion
|
||||||
if dep.Path == ImportPath {
|
simple = CustomVersion
|
||||||
module = dep
|
return
|
||||||
break
|
}
|
||||||
}
|
full = "unknown"
|
||||||
|
simple = "unknown"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// find the Caddy module in the dependency list
|
||||||
|
for _, dep := range bi.Deps {
|
||||||
|
if dep.Path == ImportPath {
|
||||||
|
module = dep
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if module != nil {
|
if module != nil {
|
||||||
|
|
Loading…
Reference in a new issue