Skip to content

Commit 1a81714

Browse files
authored
Merge pull request #2 from input-output-hk/nm/error-reporting
Improve error reporting in changelogs subcommand
2 parents 806d2ac + 2145588 commit 1a81714

File tree

11 files changed

+107
-108
lines changed

11 files changed

+107
-108
lines changed

.github/workflows/haskell.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ jobs:
5252

5353
- name: Run tests
5454
run: cabal test all
55+
56+
- name: Lint changelogs
57+
run: |
58+
cabal run -- clrt changelogs -i $(git ls-files '*CHANGELOG.md')
59+
git diff --exit-code

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Changelog
2+
3+
Version history for `cardano-ledger-release-tool`
4+
5+
## 0.1.1.0
6+
7+
* Add a `--version` option
8+
* Shorten executable name to `clrt`
9+
10+
### changelogs
11+
12+
* Improve error reporting
13+
- Catch and report IO exceptions
14+
- Exit with a failure if exceptions or errors occurred
15+
* Stop appending an extra blank line when writing to stdout
16+
17+
## 0.1.0.0
18+
19+
* Restructure as a single `cardano-ledger-release-tool` app with subcommands
20+
21+
## 0.0.0.0
22+
23+
### changelogs
24+
25+
* Initial release of the `changelogs` app

cabal.project

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
packages:
2-
common
3-
changelogs
4-
main
1+
packages: .

cardano-ledger-release-tool.cabal

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
cabal-version: 3.12
2+
name: cardano-ledger-release-tool
3+
version: 0.1.1.0
4+
author: Neil Mayhew <neil.mayhew@iohk.io>
5+
copyright: 2025 IOG
6+
license: Apache-2.0
7+
synopsis:
8+
Assist with release policy for cardano-ledger
9+
10+
description:
11+
This is a tool that is used by the cardano-ledger team to simplify and enforce
12+
releasing and versioning policy
13+
14+
tested-with:
15+
ghc ==8.10.7 || ==9.2.8 || ==9.4.8 || ==9.6.7 || ==9.8.4 || ==9.10.2 || ==9.12.2
16+
17+
common language
18+
default-language: Haskell2010
19+
other-extensions:
20+
ApplicativeDo
21+
OverloadedStrings
22+
RecordWildCards
23+
24+
common warnings
25+
ghc-options:
26+
-Wall
27+
-Wcompat
28+
-Wunused-packages
29+
-Werror
30+
31+
common rts
32+
ghc-options:
33+
-threaded
34+
-rtsopts
35+
-with-rtsopts=-N
36+
37+
executable clrt
38+
import: language, warnings, rts
39+
hs-source-dirs: src
40+
main-is: main.hs
41+
other-modules:
42+
Changelog
43+
Changelogs
44+
Options
45+
PackageInfo_cardano_ledger_release_tool
46+
47+
autogen-modules:
48+
PackageInfo_cardano_ledger_release_tool
49+
50+
build-depends:
51+
base,
52+
cmark,
53+
mtl,
54+
optparse-applicative,
55+
pretty-simple,
56+
terminal-size,
57+
text,
58+
unliftio,

changelogs/changelogs.cabal

Lines changed: 0 additions & 35 deletions
This file was deleted.

common/common.cabal

Lines changed: 0 additions & 25 deletions
This file was deleted.

main/main.cabal

Lines changed: 0 additions & 35 deletions
This file was deleted.
File renamed without changes.

changelogs/Changelogs.hs renamed to src/Changelogs.hs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
module Changelogs (subcmd) where
66

77
import Changelog
8-
import Data.Foldable (for_)
8+
import Control.Monad (when, (<=<))
9+
import Data.Bitraversable (bitraverse)
10+
import Data.Either (isLeft)
911
import Data.Functor ((<&>))
1012
import Data.Text.Lazy (Text, unpack)
13+
import Data.Traversable (for)
1114
import Options.Applicative
12-
import System.IO (stderr)
15+
import System.Exit (exitFailure)
16+
import System.IO (hPrint, stderr)
17+
import UnliftIO.Exception (tryAny)
1318

1419
import qualified Data.Text.Lazy as TL
1520
import qualified Data.Text.Lazy.IO as TL
@@ -39,7 +44,7 @@ options =
3944
<> metavar "FILE"
4045
stdoutParser =
4146
-- Write output to stdout
42-
pure $ const TL.putStrLn
47+
pure $ const TL.putStr
4348
optWriteFile <- inplaceParser <|> fileParser <|> stdoutParser
4449
optBulletHierarchy <-
4550
strOption $
@@ -61,8 +66,10 @@ subcmd :: Mod CommandFields (Global.Options -> IO ())
6166
subcmd =
6267
command "changelogs" $
6368
options <&> \Options {..} Global.Options {} -> do
64-
for_ optChangelogs $ \fp -> do
65-
let
66-
printError e = TL.hPutStrLn stderr $ TL.pack fp <> ": " <> e
67-
writeLog = optWriteFile fp . renderChangelog optBulletHierarchy
68-
either printError writeLog . parseChangelog =<< TL.readFile fp
69+
failure <- fmap (any isLeft) . for optChangelogs $ \fp -> do
70+
bitraverse (hPrint stderr) pure <=< tryAny $ do
71+
let
72+
throwError e = errorWithoutStackTrace $ fp <> ": " <> TL.unpack e
73+
writeLog = optWriteFile fp . renderChangelog optBulletHierarchy
74+
either throwError writeLog . parseChangelog =<< TL.readFile fp
75+
when failure exitFailure
File renamed without changes.

0 commit comments

Comments
 (0)