Skip to content

Commit

Permalink
Fix issue attempting to access empty string
Browse files Browse the repository at this point in the history
Also remove code duplication
  • Loading branch information
joshuacolvin0 committed Oct 26, 2023
1 parent e8f0619 commit ed5694b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/daserver/daserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func startup() error {
dasLifecycleManager.Register(&L1ReaderCloser{l1Reader})
}

vcsRevision, vcsTime := confighelpers.GetVersion()
vcsRevision, _, vcsTime := confighelpers.GetVersion()
var rpcServer *http.Server
if serverConfig.EnableRPC {
log.Info("Starting HTTP-RPC server", "addr", serverConfig.RPCAddr, "port", serverConfig.RPCPort, "revision", vcsRevision, "vcs.time", vcsTime)
Expand Down
9 changes: 7 additions & 2 deletions cmd/genericconf/getversion18.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package genericconf

import "runtime/debug"

func GetVersion(definedVersion string, definedTime string, definedModified string) (string, string) {
func GetVersion(definedVersion string, definedTime string, definedModified string) (string, string, string) {
vcsVersion := "development"
vcsTime := "development"
vcsModified := "false"
Expand Down Expand Up @@ -43,5 +43,10 @@ func GetVersion(definedVersion string, definedTime string, definedModified strin
vcsVersion = vcsVersion + "-modified"
}

return vcsVersion, vcsTime
strippedVersion := vcsVersion
if len(strippedVersion) > 0 && strippedVersion[0] == 'v' {
strippedVersion = strippedVersion[1:]
}

return vcsVersion, strippedVersion, vcsTime
}
8 changes: 2 additions & 6 deletions cmd/nitro-val/nitro_val.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ func mainImpl() int {
stackConf.P2P.ListenAddr = ""
stackConf.P2P.NoDial = true
stackConf.P2P.NoDiscovery = true
vcsRevision, vcsTime := confighelpers.GetVersion()
stackConf.Version = vcsRevision
if stackConf.Version[0] == 'v' {
// Skip leading "v" in version string
stackConf.Version = stackConf.Version[1:]
}
vcsRevision, strippedRevision, vcsTime := confighelpers.GetVersion()
stackConf.Version = strippedRevision

pathResolver := func(workdir string) func(string) string {
if workdir == "" {
Expand Down
8 changes: 2 additions & 6 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,8 @@ func mainImpl() int {
stackConf.P2P.ListenAddr = ""
stackConf.P2P.NoDial = true
stackConf.P2P.NoDiscovery = true
vcsRevision, vcsTime := confighelpers.GetVersion()
stackConf.Version = vcsRevision
if stackConf.Version[0] == 'v' {
// Skip leading "v" in version string
stackConf.Version = stackConf.Version[1:]
}
vcsRevision, strippedRevision, vcsTime := confighelpers.GetVersion()
stackConf.Version = strippedRevision

pathResolver := func(workdir string) func(string) string {
if workdir == "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func startup() error {
glogger.Verbosity(log.Lvl(relayConfig.LogLevel))
log.Root().SetHandler(glogger)

vcsRevision, vcsTime := confighelpers.GetVersion()
vcsRevision, _, vcsTime := confighelpers.GetVersion()
log.Info("Running Arbitrum nitro relay", "revision", vcsRevision, "vcs.time", vcsTime)

defer log.Info("Cleanly shutting down relay")
Expand Down
4 changes: 2 additions & 2 deletions cmd/util/confighelpers/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ func loadS3Variables(k *koanf.Koanf) error {

var ErrVersion = errors.New("configuration: version requested")

func GetVersion() (string, string) {
func GetVersion() (string, string, string) {
return genericconf.GetVersion(version, datetime, modified)
}

func PrintErrorAndExit(err error, usage func(string)) {
vcsRevision, vcsTime := GetVersion()
vcsRevision, _, vcsTime := GetVersion()
fmt.Printf("Version: %v, time: %v\n", vcsRevision, vcsTime)
if err != nil && errors.Is(err, ErrVersion) {
// Already printed version, just exit
Expand Down

0 comments on commit ed5694b

Please sign in to comment.