4
4
package tmpnet
5
5
6
6
import (
7
+ "bytes"
7
8
"context"
8
9
"encoding/base64"
9
10
"encoding/hex"
@@ -1066,7 +1067,7 @@ func checkVMBinaries(log logging.Logger, subnets []*Subnet, avalanchegoPath stri
1066
1067
return nil
1067
1068
}
1068
1069
1069
- avalanchegoRPCVersion , err := getRPCVersion (avalanchegoPath , "--version-json" )
1070
+ avalanchegoRPCVersion , err := getRPCVersion (log , avalanchegoPath , "--version-json" )
1070
1071
if err != nil {
1071
1072
log .Warn ("unable to check rpcchainvm version for avalanchego" , zap .Error (err ))
1072
1073
return nil
@@ -1092,7 +1093,7 @@ func checkVMBinaries(log logging.Logger, subnets []*Subnet, avalanchegoPath stri
1092
1093
}
1093
1094
1094
1095
// Check that the VM's rpcchainvm version matches avalanchego's version
1095
- vmRPCVersion , err := getRPCVersion (vmPath , chain .VersionArgs ... )
1096
+ vmRPCVersion , err := getRPCVersion (log , vmPath , chain .VersionArgs ... )
1096
1097
if err != nil {
1097
1098
log .Warn ("unable to check rpcchainvm version for VM Binary" ,
1098
1099
zap .String ("subnet" , subnet .Name ),
@@ -1123,12 +1124,23 @@ type RPCChainVMVersion struct {
1123
1124
1124
1125
// getRPCVersion attempts to invoke the given command with the specified version arguments and
1125
1126
// retrieve an rpcchainvm version from its output.
1126
- func getRPCVersion (command string , versionArgs ... string ) (uint64 , error ) {
1127
+ func getRPCVersion (log logging. Logger , command string , versionArgs ... string ) (uint64 , error ) {
1127
1128
cmd := exec .Command (command , versionArgs ... )
1128
1129
output , err := cmd .CombinedOutput ()
1129
1130
if err != nil {
1130
1131
return 0 , fmt .Errorf ("command %q failed with output: %s" , command , output )
1131
1132
}
1133
+
1134
+ // Ignore output before the opening brace to tolerate the case of a command being invoked
1135
+ // with `go run` and the go toolchain emitting diagnostic logging before the version output.
1136
+ if idx := bytes .IndexByte (output , '{' ); idx > 0 {
1137
+ log .Info ("ignoring leading bytes of JSON version output in advance of opening `{`" ,
1138
+ zap .String ("command" , command ),
1139
+ zap .String ("ignoredLeadingBytes" , string (output [:idx ])),
1140
+ )
1141
+ output = output [idx :]
1142
+ }
1143
+
1132
1144
version := & RPCChainVMVersion {}
1133
1145
if err := json .Unmarshal (output , version ); err != nil {
1134
1146
return 0 , fmt .Errorf ("failed to unmarshal output from command %q: %w, output: %s" , command , err , output )
0 commit comments