module Proteome.Data.FilenameError where

import Exon (exon)
import Log (Severity (Error, Warn))
import Ribosome (Report (Report), Reportable (toReport))

data FilenameError =
  BadCwd
  |
  InvalidPathSpec Text
  |
  BufferPathInvalid
  |
  CreateDir Text
  |
  Exists Text
  |
  ActionFailed Text Text
  |
  Remove Text
  deriving stock (FilenameError -> FilenameError -> Bool
(FilenameError -> FilenameError -> Bool)
-> (FilenameError -> FilenameError -> Bool) -> Eq FilenameError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FilenameError -> FilenameError -> Bool
$c/= :: FilenameError -> FilenameError -> Bool
== :: FilenameError -> FilenameError -> Bool
$c== :: FilenameError -> FilenameError -> Bool
Eq, Int -> FilenameError -> ShowS
[FilenameError] -> ShowS
FilenameError -> String
(Int -> FilenameError -> ShowS)
-> (FilenameError -> String)
-> ([FilenameError] -> ShowS)
-> Show FilenameError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FilenameError] -> ShowS
$cshowList :: [FilenameError] -> ShowS
show :: FilenameError -> String
$cshow :: FilenameError -> String
showsPrec :: Int -> FilenameError -> ShowS
$cshowsPrec :: Int -> FilenameError -> ShowS
Show, (forall x. FilenameError -> Rep FilenameError x)
-> (forall x. Rep FilenameError x -> FilenameError)
-> Generic FilenameError
forall x. Rep FilenameError x -> FilenameError
forall x. FilenameError -> Rep FilenameError x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FilenameError x -> FilenameError
$cfrom :: forall x. FilenameError -> Rep FilenameError x
Generic)

instance Reportable FilenameError where
  toReport :: FilenameError -> Report
toReport = \case
    FilenameError
BadCwd ->
      HasCallStack => Text -> [Text] -> Severity -> Report
Text -> [Text] -> Severity -> Report
Report Text
"Could not determine current directory" [Item [Text]
"FilenameError.BadCwd"] Severity
Error
    InvalidPathSpec Text
spec ->
      HasCallStack => Text -> [Text] -> Severity -> Report
Text -> [Text] -> Severity -> Report
Report [exon|Invalid path: #{spec}|] [Item [Text]
"FilenameError.InvalidPathSpec:", Text
Item [Text]
spec] Severity
Warn
    FilenameError
BufferPathInvalid ->
      HasCallStack => Text -> [Text] -> Severity -> Report
Text -> [Text] -> Severity -> Report
Report Text
"Current buffer is not an existing file" [Item [Text]
"FilenameError.BufferPathInvalid"] Severity
Warn
    CreateDir Text
dir ->
      HasCallStack => Text -> [Text] -> Severity -> Report
Text -> [Text] -> Severity -> Report
Report [exon|Could not create directory #{dir}|] [Item [Text]
"FilenameError.CreateDir:", Text
Item [Text]
dir] Severity
Warn
    Exists Text
file ->
      HasCallStack => Text -> [Text] -> Severity -> Report
Text -> [Text] -> Severity -> Report
Report [exon|File already exists: #{file}|] [Item [Text]
"FilenameError.Exists:", Text
Item [Text]
file] Severity
Warn
    ActionFailed Text
action Text
err ->
      HasCallStack => Text -> [Text] -> Severity -> Report
Text -> [Text] -> Severity -> Report
Report Text
"File system error" [Item [Text]
"FilenameError.ActionFailed:", Text
Item [Text]
action, Text
Item [Text]
err] Severity
Warn
    Remove Text
err ->
      HasCallStack => Text -> [Text] -> Severity -> Report
Text -> [Text] -> Severity -> Report
Report Text
"Couldn't remove the source file" [Item [Text]
"FilenameError.Remove:", Text
Item [Text]
err] Severity
Warn