Repository: coinbase/rosetta-cli
Pull request #257 (2021-11-18 19:41:16)

flag to print out error stack
Fixes # .

### Motivation
When check data/construction fails, there's no way to see where the error came from in the code.

### Solution
This PR adds a flag which when enabled will print the error stack. 
Eventually we should also be able to print error stack from rosetta-sdk-go package for deeper debugging but that will be a different change.

### Open questions
<!--
(optional) Any open questions or feedback on design desired?
-->


coveralls: ## Pull Request Test Coverage Report for [Build 7317](https://coveralls.io/builds/44382791)

* **1** of **11**   **(9.09%)**  changed or added relevant lines in **2** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage decreased (**-0.2%**) to **41.983%**

---

|  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
| :-----|--------------|--------|---: |
| [pkg/results/construction_results.go](https://coveralls.io/builds/44382791/source?filename=pkg%2Fresults%2Fconstruction_results.go#L88) | 0 | 4 | 0.0%
| [pkg/results/data_results.go](https://coveralls.io/builds/44382791/source?filename=pkg%2Fresults%2Fdata_results.go#L313) | 1 | 7 | 14.29%
<!-- | **Total:** | **1** | **11** | **9.09%** | -->


|  Totals | [![Coverage Status](https://coveralls.io/builds/44382791/badge)](https://coveralls.io/builds/44382791) |
| :-- | --: |
| Change from base [Build 7289](https://coveralls.io/builds/44281639): |  -0.2% |
| Covered Lines: | 707 |
| Relevant Lines: | 1684 |

---
##### 💛  - [Coveralls](https://coveralls.io)

septerr: Do we need a flag? Should we always print the stacktrace?
shrimalmadhur: > Do we need a flag? Should we always print the stacktrace?

Ya I thought about it before. but eventually I am also planning to bubble up errors from rosetta-sdk-go. So I thought of giving a configurable option to enable and disable it so that if someone doesn't want to see stack trace. I mean in some sense it's always helpful when there are errors but I also wanted to give an option to not log so much stack trace. we could also enable it by default rather than disabling it.

Patch:
diff --git a/configuration/types.go b/configuration/types.go
index 817608a..95cc620 100644
--- a/configuration/types.go
+++ b/configuration/types.go
@@ -421,6 +421,10 @@ type Configuration struct {
 	// specific validation will be done
 	ValidationFile string `json:"validation_file,omitempty"`
 
+	// ErrorStackTraceEnabled if true then it will print error stack trace
+	// if the data or construction check fails
+	ErrorStackTraceEnabled bool `json:"error_stack_trace_enabled"`
+
 	Construction *ConstructionConfiguration `json:"construction"`
 	Data         *DataConfiguration         `json:"data"`
 }
diff --git a/examples/configuration/default.json b/examples/configuration/default.json
index 1d5a448..91dabf3 100644
--- a/examples/configuration/default.json
+++ b/examples/configuration/default.json
@@ -15,6 +15,7 @@
  "log_configuration": false,
  "compression_disabled": false,
  "memory_limit_disabled": false,
+ "error_stack_trace_enabled": false,
  "construction": null,
  "data": {
   "active_reconciliation_concurrency": 16,
diff --git a/go.mod b/go.mod
index 17f9826..25fcab9 100644
--- a/go.mod
+++ b/go.mod
@@ -6,6 +6,7 @@ require (
 	github.com/coinbase/rosetta-sdk-go v0.7.1
 	github.com/fatih/color v1.13.0
 	github.com/olekukonko/tablewriter v0.0.5
+	github.com/pkg/errors v0.9.1
 	github.com/spf13/cobra v1.2.1
 	github.com/stretchr/testify v1.7.0
 	golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
diff --git a/pkg/results/construction_results.go b/pkg/results/construction_results.go
index 22f8b65..82957c3 100644
--- a/pkg/results/construction_results.go
+++ b/pkg/results/construction_results.go
@@ -21,6 +21,8 @@ import (
 	"os"
 	"strconv"
 
+	pkgError "github.com/pkg/errors"
+
 	"github.com/coinbase/rosetta-cli/configuration"
 
 	"github.com/coinbase/rosetta-sdk-go/storage/modules"
@@ -83,7 +85,7 @@ func ComputeCheckConstructionResults(
 	}
 
 	if err != nil {
-		results.Error = err.Error()
+		results.Error = fmt.Sprintf("%+v", err)
 
 		// We never want to populate an end condition
 		// if there was an error!
@@ -291,7 +293,7 @@ func FetchCheckConstructionStatus(url string) (*CheckConstructionStatus, error)
 	return &status, nil
 }
 
-// ExitConstruction exits check:data, logs the test results to the console,
+// ExitConstruction exits check:construction, logs the test results to the console,
 // and to a provided output path.
 func ExitConstruction(
 	config *configuration.Configuration,
@@ -299,6 +301,10 @@ func ExitConstruction(
 	jobStorage *modules.JobStorage,
 	err error,
 ) error {
+	if config.ErrorStackTraceEnabled {
+		err = pkgError.WithStack(err)
+	}
+
 	results := ComputeCheckConstructionResults(
 		config,
 		err,
diff --git a/pkg/results/data_results.go b/pkg/results/data_results.go
index e2aca1c..b765174 100644
--- a/pkg/results/data_results.go
+++ b/pkg/results/data_results.go
@@ -23,6 +23,8 @@ import (
 	"os"
 	"strconv"
 
+	pkgError "github.com/pkg/errors"
+
 	"github.com/coinbase/rosetta-cli/configuration"
 
 	"github.com/coinbase/rosetta-sdk-go/asserter"
@@ -308,7 +310,7 @@ func ComputeCheckDataProgress(
 
 	genesisBlockIndex := int64(0)
 	if networkStatus.GenesisBlockIdentifier != nil {
-		genesisBlockIndex =  networkStatus.GenesisBlockIdentifier.Index
+		genesisBlockIndex = networkStatus.GenesisBlockIdentifier.Index
 	}
 
 	// Get current tip in the case that re-orgs occurred
@@ -368,8 +370,8 @@ func ComputeCheckDataProgress(
 	blocksSynced := new(
 		big.Float,
 	).Quo(
-		new(big.Float).SetInt64(headBlock.Index - genesisBlockIndex),
-		new(big.Float).SetInt64(tipIndex - genesisBlockIndex),
+		new(big.Float).SetInt64(headBlock.Index-genesisBlockIndex),
+		new(big.Float).SetInt64(tipIndex-genesisBlockIndex),
 	)
 	blocksSyncedFloat, _ := blocksSynced.Float64()
 
@@ -669,7 +671,7 @@ func ComputeCheckDataResults(
 	}
 
 	if err != nil {
-		results.Error = err.Error()
+		results.Error = fmt.Sprintf("%+v", err)
 
 		// If all tests pass, but we still encountered an error,
 		// then we hard exit without showing check:data results
@@ -707,6 +709,10 @@ func ExitData(
 	endCondition configuration.CheckDataEndCondition,
 	endConditionDetail string,
 ) error {
+	if config.ErrorStackTraceEnabled {
+		err = pkgError.WithStack(err)
+	}
+
 	results := ComputeCheckDataResults(
 		config,
 		err,


Test patch:
diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go
index bdc9125..9328be0 100644
--- a/configuration/configuration_test.go
+++ b/configuration/configuration_test.go
@@ -62,15 +62,16 @@ var (
 			Blockchain: "sweet",
 			Network:    "sweeter",
 		},
-		OnlineURL:            "http://hasudhasjkdk",
-		MaxOnlineConnections: 10,
-		HTTPTimeout:          21,
-		MaxRetries:           1000,
-		MaxSyncConcurrency:   12,
-		TipDelay:             1231,
-		MaxReorgDepth:        12,
-		SeenBlockWorkers:     300,
-		SerialBlockWorkers:   200,
+		OnlineURL:              "http://hasudhasjkdk",
+		MaxOnlineConnections:   10,
+		HTTPTimeout:            21,
+		MaxRetries:             1000,
+		MaxSyncConcurrency:     12,
+		TipDelay:               1231,
+		MaxReorgDepth:          12,
+		SeenBlockWorkers:       300,
+		SerialBlockWorkers:     200,
+		ErrorStackTraceEnabled: true,
 		Construction: &ConstructionConfiguration{
 			OfflineURL:            "https://ashdjaksdkjshdk",
 			MaxOfflineConnections: 21,