@marcel91200 / caddy Mirror · read-only / commits / c3b5b181
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 13, 08:00 UTC

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

Lukas Vogel committed Dec 19, 2022 at 22:23 UTC c3b5b1811c119b896c5f70e3275ca835e7df5460
1 file changed +15 -7
caddy.go
+15 -7
@@ -864,13 +864,21 @@ func Version() (simple, full string) {
864 // bi.Main... hopefully.
865 var module *debug.Module
866 bi, ok := debug.ReadBuildInfo()
867 - if ok {
868 - // find the Caddy module in the dependency list
869 - for _, dep := range bi.Deps {
870 - if dep.Path == ImportPath {
871 - module = dep
872 - break
873 - }
867 + if !ok {
868 + if CustomVersion != "" {
869 + full = CustomVersion
870 + simple = CustomVersion
871 + return
872 + }
873 + full = "unknown"
874 + simple = "unknown"
875 + return
876 + }
877 + // find the Caddy module in the dependency list
878 + for _, dep := range bi.Deps {
879 + if dep.Path == ImportPath {
880 + module = dep
881 + break
882 }
883 }
884 if module != nil {