From 271a403a4fe4509c8b42d16a17d976e3bb1796d7 Mon Sep 17 00:00:00 2001 From: Krisztian Pinter Date: Tue, 24 Sep 2024 17:06:13 +0200 Subject: [PATCH 1/2] Fix CLI returning incorrect exit status --- CHANGELOG.md | 6 ++++++ offchain/README.md | 8 ++++---- offchain/src/Main.purs | 14 +++++++++----- .../TrustlessSidechain/Effects/Transaction.purs | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67221c8b..d702ce12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 not returning correct error status on failure + # v6.1.0 ## Added diff --git a/offchain/README.md b/offchain/README.md index 84738994..be3f77eb 100644 --- a/offchain/README.md +++ b/offchain/README.md @@ -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: @@ -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 \ diff --git a/offchain/src/Main.purs b/offchain/src/Main.purs index 567a2e64..efd06f67 100644 --- a/offchain/src/Main.purs +++ b/offchain/src/Main.purs @@ -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) @@ -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 @@ -157,9 +158,9 @@ 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 @@ -167,6 +168,9 @@ main = do 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 diff --git a/offchain/src/TrustlessSidechain/Effects/Transaction.purs b/offchain/src/TrustlessSidechain/Effects/Transaction.purs index 2a8f8e7e..a94640d5 100644 --- a/offchain/src/TrustlessSidechain/Effects/Transaction.purs +++ b/offchain/src/TrustlessSidechain/Effects/Transaction.purs @@ -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 From 430377900a86211270fa6092779444c0efe4179c Mon Sep 17 00:00:00 2001 From: Krisztian Pinter Date: Wed, 25 Sep 2024 09:56:49 +0200 Subject: [PATCH 2/2] address review --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d702ce12..194d7a65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ Changelog](https://keepachangelog.com/en/1.1.0). * 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 not returning correct error status on failure + * CLI now returns non-zero exit code on failure # v6.1.0