hledger-lib 1.43.1 → 1.43.2
raw patch · 3 files changed
+46/−24 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Hledger.Utils.IO: exitOnError :: IO () -> IO ()
+ Hledger.Utils.IO: handleExit :: IO () -> IO ()
Files
- CHANGES.md +5/−0
- Hledger/Utils/IO.hs +40/−23
- hledger-lib.cabal +1/−1
CHANGES.md view
@@ -22,6 +22,11 @@ For user-visible changes, see the hledger package changelog. +# 1.43.2 2025-06-13++- Hledger.Utils.IO: rename exitOnError -> handleExit, improve doc++ # 1.43.1 2025-06-04 - Hledger.Query: queryIsAmtOrSym
Hledger/Utils/IO.hs view
@@ -9,6 +9,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PackageImports #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE MultiWayIf #-} module Hledger.Utils.IO ( @@ -26,7 +27,7 @@ ansiFormatWarning, printError, exitWithErrorMessage,- exitOnError,+ handleExit, -- * Time getCurrentLocalTime,@@ -261,43 +262,59 @@ exitWithErrorMessage :: String -> IO () exitWithErrorMessage msg = printError msg >> exitFailure --- | This wraps a program's main routine so as to display more consistent--- and useful error output for some common program-terminating exceptions,--- independent of compiler version. It catches:+-- | This wraps a program's main routine so as to display more consistent,+-- useful, and GHC-version-independent error output when the program exits+-- because of certain common exceptions. It ----- - UnicodeException - unicode errors in pure code+-- 1. disables SIGPIPE errors, which are usually harmless,+-- caused when our output is truncated in a piped command. ----- - IOException AKA IOError - I/O errors, including unicode errors during I/O+-- 2. catches these common exceptions: ----- - ErrorCall - @error@ / @errorWithoutStackTrace@ calls+-- - UnicodeException, caused eg by text decoding errors in pure code ----- and:--- --- - removes the trailing newlines added by some GHC 9.10.*+-- - IOException, caused by I/O errors, including text decoding errors during I/O ----- - removes "uncaught exception" output added by some GHC 9.12.*+-- - ErrorCall - @error@ / @errorWithoutStackTrace@ calls ----- - ensures a consistent "programname: " prefix+-- 3. compensates for GHC output bugs: ----- - applies ANSI styling (bold bright red) to the first line if that is supported and allowed+-- - removes the trailing newlines added by some GHC 9.10.* versions ----- - for unicode exceptions, and I/O exceptions which look like they were--- caused by a unicode error (usually text decoding failure),--- it adds (english) text explaining the problem and what to do.+-- - removes "uncaught exception" output added by some GHC 9.12.* versions ----- Some exceptions this does not handle:--- ExitCode (exitSuccess / exitFailure / exitWith calls)+-- - ensures a consistent "PROGNAME: " prefix+--+-- 4. applies bold bright red ANSI styling to the first line of error output,+-- if that is supported and allowed+--+-- 5. for unicode exceptions and I/O exceptions which look like they were+-- unicode-related, it adds a message (in english) explaining the problem and what to do.+--+-- Some exceptions this does not catch are ExitCode (exitSuccess/exitFailure/exitWith) -- and UserInterrupt (control-C). ---exitOnError :: IO () -> IO ()-exitOnError = flip catches- [-- Handler (\(e::SomeException) -> error' $ pshow e), -- debug+handleExit :: IO () -> IO ()+handleExit = flip catches [+ -- Handler (\(e::SomeException) -> error' $ pshow e), -- debug Handler (\(e::UnicodeException) -> exitUnicode e)- ,Handler (\(e::IOException) -> if isUnicodeError e then exitUnicode e else exitOther e)+ ,Handler (\(e::IOException) -> if+ | isUnicodeError e -> exitUnicode e+ | otherwise -> exitOther e) ,Handler (\(e::ErrorCall) -> exitOther e)- ]+ ] . ignoreSigPipe where+ -- | Ignore SIGPIPE errors.+ -- This is copied from System.Process.Internals in process 1.6.20.0+,+ -- since that version of process comes only with ghc 9.10.2+.+ ignoreSigPipe :: IO () -> IO ()+ ignoreSigPipe = handle $ \e -> case e of+ IOError { ioe_type = ResourceVanished+ , ioe_errno = Just ioe }+ | Errno ioe == ePIPE -> return ()+ _ -> throwIO e+ -- Many decoding failures do not produce a UnicodeException, unfortunately. -- So this fragile hack detects them from the error message. -- But there are many variant wordings and they probably change over time.
hledger-lib.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: hledger-lib-version: 1.43.1+version: 1.43.2 synopsis: A library providing the core functionality of hledger description: This library contains hledger's core functionality. It is used by most hledger* packages so that they support the same