Skip to content

Commit d4adf7a

Browse files
committed
[FAB-5141] configtxgen --version should not panic
If configtxgen cannot find a configtx.yaml file, it panics. While this in and of itself is ok, it should not panic when simply trying to get the version. Two changes were made: - move response to --version above all other flags - added a defer / recover function to better handle config not found and make things more clear Change-Id: I512d1fed464c734db7178eb576440c45767f6994 Signed-off-by: Gari Singh <[email protected]>
1 parent ace2a64 commit d4adf7a

File tree

1 file changed

+19
-5
lines changed
  • common/configtx/tool/configtxgen

1 file changed

+19
-5
lines changed

common/configtx/tool/configtxgen/main.go

+19-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"io/ioutil"
2525
"os"
26+
"strings"
2627

2728
"github.com/hyperledger/fabric/bccsp/factory"
2829
"github.com/hyperledger/fabric/common/config"
@@ -347,17 +348,30 @@ func main() {
347348

348349
flag.Parse()
349350

351+
// show version
352+
if *version {
353+
printVersion()
354+
os.Exit(exitCode)
355+
}
356+
350357
logging.SetLevel(logging.INFO, "")
351358

359+
// don't need to panic when running via command line
360+
defer func() {
361+
if err := recover(); err != nil {
362+
if strings.Contains(fmt.Sprint(err), "Error reading configuration: Unsupported Config Type") {
363+
logger.Error("Could not find configtx.yaml. " +
364+
"Please make sure that FABRIC_CFG_PATH is set to a path " +
365+
"which contains configtx.yaml")
366+
}
367+
os.Exit(1)
368+
}
369+
}()
370+
352371
logger.Info("Loading configuration")
353372
factory.InitFactories(nil)
354373
config := genesisconfig.Load(profile)
355374

356-
if *version {
357-
printVersion()
358-
os.Exit(exitCode)
359-
}
360-
361375
if outputBlock != "" {
362376
if err := doOutputBlock(config, channelID, outputBlock); err != nil {
363377
logger.Fatalf("Error on outputBlock: %s", err)

0 commit comments

Comments
 (0)