-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `Exception` instance for `HpackException` preserves the existing error messages of all existing Hpack exceptions in the `displayException` functions. Updates tests accordingly. Some tests use `shouldSatisfy` rather than `shouldReturn` as `HpackException` cannot be an instance of `Eq`. Moves `ProgramName` from `Hpack.Config` to new module `Hpack.ProgramName` because `Hpack.Exception` needs to import the type and `Hpack.Config` now imports `Hpack.Exception`. Also bumps Hpack's `stack.yaml` to use lts-20.0 (GHC 9.2.5) rather than lts-15.11 (GHC 8.8.3).
- Loading branch information
Showing
13 changed files
with
253 additions
and
105 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{-# LANGUAGE RecordWildCards #-} | ||
|
||
-- | Exceptions thrown by the Hpack library. | ||
module Hpack.Exception | ||
( HpackException (..) | ||
-- * Re-export of types used in Hpack exceptions | ||
, FilePath | ||
, ParseException (..) | ||
, ProgramName (..) | ||
, Status (..) | ||
, Version (..) | ||
, URL | ||
, YamlException (..) | ||
, YamlMark (..) | ||
) where | ||
|
||
import Control.Exception (Exception (..)) | ||
import qualified Data.ByteString.Char8 as B | ||
import Data.List (intercalate) | ||
import Data.Typeable (Typeable) | ||
import Data.Version (Version (..), showVersion) | ||
import Data.Yaml | ||
(ParseException (..), YamlException (..), YamlMark (..)) | ||
import Network.HTTP.Types.Status (Status (..)) | ||
|
||
import Hpack.ProgramName (ProgramName (..)) | ||
|
||
-- | Type synonyn representing URLs. | ||
type URL = String | ||
|
||
-- | Type representing exceptions thrown by functions exported by the modules of | ||
-- the Hpack library. | ||
data HpackException | ||
= CycleInDefaultsException ![FilePath] | ||
| DecodeValueException !FilePath !String | ||
| DefaultsFileNotFound !FilePath | ||
| DefaultsFileUrlNotFound !URL | ||
| DownloadingFileFailed !URL !Status | ||
| HpackParseException !FilePath !ParseException | ||
| HpackVersionUnsupported !ProgramName !FilePath !Version !Version | ||
deriving (Show, Typeable) | ||
|
||
instance Exception HpackException where | ||
displayException (CycleInDefaultsException files) = | ||
"cycle in defaults (" ++ intercalate " -> " files ++ ")" | ||
displayException (DecodeValueException file s) = | ||
file ++ ": " ++ s | ||
displayException (DefaultsFileNotFound file) = | ||
"Invalid value for \"defaults\"! File " ++ file ++ " does not exist!" | ||
displayException (DefaultsFileUrlNotFound url) = | ||
"Invalid value for \"defaults\"! File " ++ url ++ " does not exist!" | ||
displayException (DownloadingFileFailed url status) = | ||
"Error while downloading " ++ url ++ " (" ++ formatStatus status ++ ")" | ||
where | ||
formatStatus :: Status -> String | ||
formatStatus (Status code message) = show code ++ " " ++ B.unpack message | ||
displayException (HpackParseException file e) = file ++ case e of | ||
AesonException s -> ": " ++ s | ||
InvalidYaml (Just (YamlException s)) -> ": " ++ s | ||
InvalidYaml (Just (YamlParseException{..})) -> | ||
let YamlMark{..} = yamlProblemMark | ||
in ":" ++ show yamlLine ++ ":" ++ show yamlColumn ++ ": " ++ | ||
yamlProblem ++ " " ++ yamlContext | ||
err -> ": " ++ displayException err | ||
displayException | ||
(HpackVersionUnsupported (ProgramName progName) file wanted supported) = | ||
"The file " ++ file ++ " requires version " ++ showVersion wanted ++ | ||
" of the Hpack package specification, however this version of " ++ | ||
progName ++ " only supports versions up to " ++ showVersion supported ++ | ||
". Upgrading to the latest version of " ++ progName ++ | ||
" may resolve this issue." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Hpack.ProgramName | ||
( ProgramName (..) | ||
) where | ||
|
||
import Data.String (IsString (..)) | ||
|
||
-- | Type representing the names of programs using the Hpack library. | ||
newtype ProgramName = ProgramName String | ||
deriving (Eq, Show) | ||
|
||
instance IsString ProgramName where | ||
fromString = ProgramName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
resolver: lts-15.11 | ||
resolver: lts-20.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.