-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
117 additions
and
57 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,58 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
module Hpack.Error ( | ||
HpackError (..) | ||
, hpackProgName | ||
, renderHpackError | ||
, ProgramName (..) | ||
, formatStatus | ||
-- * Re-export of types used in Hpack errors | ||
, Status (..) | ||
, URL | ||
) where | ||
|
||
import qualified Data.ByteString.Char8 as B | ||
import Data.List (intercalate) | ||
import Data.String (IsString (..)) | ||
import Data.Version (Version (..), showVersion) | ||
import Network.HTTP.Types.Status (Status (..)) | ||
|
||
type URL = String | ||
|
||
data HpackError = | ||
HpackVersionUnsupported !FilePath !Version !Version | ||
| DefaultsFileNotFound !FilePath | ||
| DefaultsFileUrlNotFound !URL | ||
| DownloadingFileFailed !URL !Status | ||
| CycleInDefaultsError ![FilePath] | ||
| HpackParseYamlException !String | ||
| DecodeValueError !FilePath !String | ||
deriving (Eq, Show) | ||
|
||
renderHpackError :: ProgramName -> HpackError -> String | ||
renderHpackError (ProgramName progName) = \ case | ||
HpackVersionUnsupported 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." | ||
DefaultsFileNotFound file -> "Invalid value for \"defaults\"! File " ++ file ++ " does not exist!" | ||
DefaultsFileUrlNotFound url -> "Invalid value for \"defaults\"! File " ++ url ++ " does not exist!" | ||
DownloadingFileFailed url status -> "Error while downloading " ++ url ++ " (" ++ formatStatus status ++ ")" | ||
CycleInDefaultsError files -> "cycle in defaults (" ++ intercalate " -> " files ++ ")" | ||
HpackParseYamlException s -> s | ||
DecodeValueError file s -> renderFileMsg file s | ||
|
||
formatStatus :: Status -> String | ||
formatStatus (Status code message) = show code ++ " " ++ B.unpack message | ||
|
||
renderFileMsg :: FilePath -> String -> String | ||
renderFileMsg file s = file ++ ": " ++ s | ||
|
||
hpackProgName :: ProgramName | ||
hpackProgName = ProgramName "hpack" | ||
|
||
newtype ProgramName = ProgramName {unProgramName :: 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