Skip to content

Commit

Permalink
ledgerutil exits with a proper code
Browse files Browse the repository at this point in the history
This patch makes ledgerutil exit with a proper code when it fails.

Signed-off-by: Taku Shimosawa <taku.shimosawa.uf@hitachi.com>
  • Loading branch information
shimos authored and manish-sethi committed Feb 17, 2022
1 parent 88c02cd commit debcd11
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cmd/ledgerutil/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,22 @@ func main() {
*outputDir, err = os.Getwd()
if err != nil {
fmt.Printf("%s%s\n", compareErrorMessage, err)
return
os.Exit(1)
}
}

count, outputDirPath, err := ledgerutil.Compare(*snapshotPath1, *snapshotPath2, *outputDir, *firstDiffs)
if err != nil {
fmt.Printf("%s%s\n", compareErrorMessage, err)
return
os.Exit(1)
}

fmt.Print("\nSuccessfully compared snapshots. ")
if count == -1 {
fmt.Println("Both snapshot public state and private state hashes were the same. No results were generated.")
} else {
fmt.Printf("Results saved to %s. Total differences found: %d\n", outputDirPath, count)
os.Exit(2)
}
}
}
6 changes: 5 additions & 1 deletion cmd/ledgerutil/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ func TestArguments(t *testing.T) {
},
"one-snapshot": {
exitCode: 1,
args: []string{"compare, snapshotDir1"},
args: []string{"compare", "snapshotDir1"},
},
"invalid-snapshot-dirs": {
exitCode: 1,
args: []string{"compare", "/non-existent/snapshot1", "/non-existent/snapshot2"},
},
}

Expand Down
8 changes: 8 additions & 0 deletions docs/source/commands/ledgerutil.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ Args:
<snapshotPath2> Second ledger snapshot directory.
```

## Exit Status

### ledgerutil compare

- `0` if the snapshots are identical
- `2` if the snapshots are not identical
- `1` if an error occurs

## Example Usage

### ledgerutil compare example
Expand Down
8 changes: 8 additions & 0 deletions docs/wrappers/ledgerutil_postscript.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Exit Status

### ledgerutil compare

- `0` if the snapshots are identical
- `2` if the snapshots are not identical
- `1` if an error occurs

## Example Usage

### ledgerutil compare example
Expand Down

0 comments on commit debcd11

Please sign in to comment.