Skip to content

Commit

Permalink
Fix CLI returning incorrect exit status (#126)
Browse files Browse the repository at this point in the history
* Fix CLI returning incorrect exit status
  • Loading branch information
kpinter-iohk authored Sep 25, 2024
1 parent e4101a3 commit 6473577
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog](https://keepachangelog.com/en/1.1.0).

# Unreleased

## Changed
* Nicer error messages from the CLI in some cases

## Removed
* Removed `init` command
* the PoC test modules were removed
Expand All @@ -13,6 +16,9 @@ Changelog](https://keepachangelog.com/en/1.1.0).
* Removed `save-root`, `committee-hash`, `committee-handover` and `collect-garbage` commands
* Removed `init-checkpoint`, `init-fuel`, `save-checkpoint`, `cbor-update-committee-message`, `cbor-merkle-root-insertion-message`, `cbor-merkle-tree-entry`, `cbor-merkle-tree`, `cbor-combined-merkle-proof`, and `cbor-plain-aggregate-public-keys` commands

## Fixed
* CLI now returns non-zero exit code on failure

# v6.1.0

## Added
Expand Down
8 changes: 4 additions & 4 deletions offchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ nix run .#pc-contracts-cli -- deregister \
--network testnet \
--ogmios-host localhost \
--ogmios-port 1442 \
--ogmios-secure false \
--ogmios-secure \
--kupo-host localhost \
--kupo-port 1337 \
--kupo-secure false \
--kupo-secure \
--payment-signing-key-file payment.skey \
--stake-signing-key-file stake.skey \
--spo-public-key aabbcc
--spo-public-key aabbcc \
--ada-based-staking
```

to:
Expand Down Expand Up @@ -385,7 +386,6 @@ reserve asset.
#### 3.2.10 Release currently available funds from an existing reserve
```
nix run .#pc-contracts-cli -- reserve-release-funds \
--total-accrued-till-now INT \
Expand Down
14 changes: 9 additions & 5 deletions offchain/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Control.Monad.Error.Class (throwError)
import Data.Array as Array
import Effect.Exception (error)
import JS.BigInt as BigInt
import Node.Process (exit)
import Options.Applicative (execParser)
import Run (EFFECT, Run)
import TrustlessSidechain.CLIVersion (versionString)
Expand Down Expand Up @@ -128,14 +129,14 @@ main = do
-----------------------
let numerator = (unwrap scParams).thresholdNumerator
let denominator = (unwrap scParams).thresholdDenominator
unless (gcd numerator denominator == one) $ throwError $ error
unless (gcd numerator denominator == one) $ failWith
$ "Threshold numerator and denominator are not coprime.\n"
<> "Numerator: "
<> BigInt.toString numerator
<> "\nDenominator: "
<> BigInt.toString denominator

unless (numerator <= denominator) $ throwError $ error
unless (numerator <= denominator) $ failWith
$ "Threshold numerator is greater than denominator.\n"
<> "Numerator: "
<> BigInt.toString numerator
Expand All @@ -157,16 +158,19 @@ main = do
opts.sidechainEndpointParams
opts.endpoint

case endpointResp of
Right resp -> liftEffect $ printEndpointResp resp
Left e -> log (show e)
liftEffect $ case endpointResp of
Right resp -> printEndpointResp resp
Left e -> failWith $ show e

UtilsOptions opts -> do
endpointResp <- runUtilsEndpoint opts.utilsOptions
printEndpointResp endpointResp

CLIVersion -> log versionString

failWith :: String -> Effect Unit
failWith errStr = log errStr *> exit 1

-- | Reads configuration file from `./config.json`, then
-- | parses CLI arguments. CLI arguments override the config files.
getOptions :: Effect Options
Expand Down
2 changes: 1 addition & 1 deletion offchain/src/TrustlessSidechain/Effects/Transaction.purs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ handleTransactionLive =
(Transaction.getUtxo oref)
MkUnbalancedTx lookups constraints f ->
f <$> withTry
(fromError "mkUnabalancedTx: ")
(fromError "mkUnbalancedTx: ")
(toUnbalancedTx <$> UnbalancedTx.mkUnbalancedTx lookups constraints)
BalanceTxWithConstraints unbalancedTx constraints f ->
f <$> withTry
Expand Down

0 comments on commit 6473577

Please sign in to comment.