{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CodeDeploy.Types.Diagnostics
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CodeDeploy.Types.Diagnostics where

import Amazonka.CodeDeploy.Types.LifecycleErrorCode
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Diagnostic information about executable scripts that are part of a
-- deployment.
--
-- /See:/ 'newDiagnostics' smart constructor.
data Diagnostics = Diagnostics'
  { -- | The last portion of the diagnostic log.
    --
    -- If available, AWS CodeDeploy returns up to the last 4 KB of the
    -- diagnostic log.
    Diagnostics -> Maybe Text
logTail :: Prelude.Maybe Prelude.Text,
    -- | The associated error code:
    --
    -- -   Success: The specified script ran.
    --
    -- -   ScriptMissing: The specified script was not found in the specified
    --     location.
    --
    -- -   ScriptNotExecutable: The specified script is not a recognized
    --     executable file type.
    --
    -- -   ScriptTimedOut: The specified script did not finish running in the
    --     specified time period.
    --
    -- -   ScriptFailed: The specified script failed to run as expected.
    --
    -- -   UnknownError: The specified script did not run for an unknown
    --     reason.
    Diagnostics -> Maybe LifecycleErrorCode
errorCode :: Prelude.Maybe LifecycleErrorCode,
    -- | The name of the script.
    Diagnostics -> Maybe Text
scriptName :: Prelude.Maybe Prelude.Text,
    -- | The message associated with the error.
    Diagnostics -> Maybe Text
message :: Prelude.Maybe Prelude.Text
  }
  deriving (Diagnostics -> Diagnostics -> Bool
(Diagnostics -> Diagnostics -> Bool)
-> (Diagnostics -> Diagnostics -> Bool) -> Eq Diagnostics
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Diagnostics -> Diagnostics -> Bool
$c/= :: Diagnostics -> Diagnostics -> Bool
== :: Diagnostics -> Diagnostics -> Bool
$c== :: Diagnostics -> Diagnostics -> Bool
Prelude.Eq, ReadPrec [Diagnostics]
ReadPrec Diagnostics
Int -> ReadS Diagnostics
ReadS [Diagnostics]
(Int -> ReadS Diagnostics)
-> ReadS [Diagnostics]
-> ReadPrec Diagnostics
-> ReadPrec [Diagnostics]
-> Read Diagnostics
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Diagnostics]
$creadListPrec :: ReadPrec [Diagnostics]
readPrec :: ReadPrec Diagnostics
$creadPrec :: ReadPrec Diagnostics
readList :: ReadS [Diagnostics]
$creadList :: ReadS [Diagnostics]
readsPrec :: Int -> ReadS Diagnostics
$creadsPrec :: Int -> ReadS Diagnostics
Prelude.Read, Int -> Diagnostics -> ShowS
[Diagnostics] -> ShowS
Diagnostics -> String
(Int -> Diagnostics -> ShowS)
-> (Diagnostics -> String)
-> ([Diagnostics] -> ShowS)
-> Show Diagnostics
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Diagnostics] -> ShowS
$cshowList :: [Diagnostics] -> ShowS
show :: Diagnostics -> String
$cshow :: Diagnostics -> String
showsPrec :: Int -> Diagnostics -> ShowS
$cshowsPrec :: Int -> Diagnostics -> ShowS
Prelude.Show, (forall x. Diagnostics -> Rep Diagnostics x)
-> (forall x. Rep Diagnostics x -> Diagnostics)
-> Generic Diagnostics
forall x. Rep Diagnostics x -> Diagnostics
forall x. Diagnostics -> Rep Diagnostics x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Diagnostics x -> Diagnostics
$cfrom :: forall x. Diagnostics -> Rep Diagnostics x
Prelude.Generic)

-- |
-- Create a value of 'Diagnostics' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'logTail', 'diagnostics_logTail' - The last portion of the diagnostic log.
--
-- If available, AWS CodeDeploy returns up to the last 4 KB of the
-- diagnostic log.
--
-- 'errorCode', 'diagnostics_errorCode' - The associated error code:
--
-- -   Success: The specified script ran.
--
-- -   ScriptMissing: The specified script was not found in the specified
--     location.
--
-- -   ScriptNotExecutable: The specified script is not a recognized
--     executable file type.
--
-- -   ScriptTimedOut: The specified script did not finish running in the
--     specified time period.
--
-- -   ScriptFailed: The specified script failed to run as expected.
--
-- -   UnknownError: The specified script did not run for an unknown
--     reason.
--
-- 'scriptName', 'diagnostics_scriptName' - The name of the script.
--
-- 'message', 'diagnostics_message' - The message associated with the error.
newDiagnostics ::
  Diagnostics
newDiagnostics :: Diagnostics
newDiagnostics =
  Diagnostics' :: Maybe Text
-> Maybe LifecycleErrorCode
-> Maybe Text
-> Maybe Text
-> Diagnostics
Diagnostics'
    { $sel:logTail:Diagnostics' :: Maybe Text
logTail = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:errorCode:Diagnostics' :: Maybe LifecycleErrorCode
errorCode = Maybe LifecycleErrorCode
forall a. Maybe a
Prelude.Nothing,
      $sel:scriptName:Diagnostics' :: Maybe Text
scriptName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:message:Diagnostics' :: Maybe Text
message = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The last portion of the diagnostic log.
--
-- If available, AWS CodeDeploy returns up to the last 4 KB of the
-- diagnostic log.
diagnostics_logTail :: Lens.Lens' Diagnostics (Prelude.Maybe Prelude.Text)
diagnostics_logTail :: (Maybe Text -> f (Maybe Text)) -> Diagnostics -> f Diagnostics
diagnostics_logTail = (Diagnostics -> Maybe Text)
-> (Diagnostics -> Maybe Text -> Diagnostics)
-> Lens Diagnostics Diagnostics (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Diagnostics' {Maybe Text
logTail :: Maybe Text
$sel:logTail:Diagnostics' :: Diagnostics -> Maybe Text
logTail} -> Maybe Text
logTail) (\s :: Diagnostics
s@Diagnostics' {} Maybe Text
a -> Diagnostics
s {$sel:logTail:Diagnostics' :: Maybe Text
logTail = Maybe Text
a} :: Diagnostics)

-- | The associated error code:
--
-- -   Success: The specified script ran.
--
-- -   ScriptMissing: The specified script was not found in the specified
--     location.
--
-- -   ScriptNotExecutable: The specified script is not a recognized
--     executable file type.
--
-- -   ScriptTimedOut: The specified script did not finish running in the
--     specified time period.
--
-- -   ScriptFailed: The specified script failed to run as expected.
--
-- -   UnknownError: The specified script did not run for an unknown
--     reason.
diagnostics_errorCode :: Lens.Lens' Diagnostics (Prelude.Maybe LifecycleErrorCode)
diagnostics_errorCode :: (Maybe LifecycleErrorCode -> f (Maybe LifecycleErrorCode))
-> Diagnostics -> f Diagnostics
diagnostics_errorCode = (Diagnostics -> Maybe LifecycleErrorCode)
-> (Diagnostics -> Maybe LifecycleErrorCode -> Diagnostics)
-> Lens
     Diagnostics
     Diagnostics
     (Maybe LifecycleErrorCode)
     (Maybe LifecycleErrorCode)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Diagnostics' {Maybe LifecycleErrorCode
errorCode :: Maybe LifecycleErrorCode
$sel:errorCode:Diagnostics' :: Diagnostics -> Maybe LifecycleErrorCode
errorCode} -> Maybe LifecycleErrorCode
errorCode) (\s :: Diagnostics
s@Diagnostics' {} Maybe LifecycleErrorCode
a -> Diagnostics
s {$sel:errorCode:Diagnostics' :: Maybe LifecycleErrorCode
errorCode = Maybe LifecycleErrorCode
a} :: Diagnostics)

-- | The name of the script.
diagnostics_scriptName :: Lens.Lens' Diagnostics (Prelude.Maybe Prelude.Text)
diagnostics_scriptName :: (Maybe Text -> f (Maybe Text)) -> Diagnostics -> f Diagnostics
diagnostics_scriptName = (Diagnostics -> Maybe Text)
-> (Diagnostics -> Maybe Text -> Diagnostics)
-> Lens Diagnostics Diagnostics (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Diagnostics' {Maybe Text
scriptName :: Maybe Text
$sel:scriptName:Diagnostics' :: Diagnostics -> Maybe Text
scriptName} -> Maybe Text
scriptName) (\s :: Diagnostics
s@Diagnostics' {} Maybe Text
a -> Diagnostics
s {$sel:scriptName:Diagnostics' :: Maybe Text
scriptName = Maybe Text
a} :: Diagnostics)

-- | The message associated with the error.
diagnostics_message :: Lens.Lens' Diagnostics (Prelude.Maybe Prelude.Text)
diagnostics_message :: (Maybe Text -> f (Maybe Text)) -> Diagnostics -> f Diagnostics
diagnostics_message = (Diagnostics -> Maybe Text)
-> (Diagnostics -> Maybe Text -> Diagnostics)
-> Lens Diagnostics Diagnostics (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Diagnostics' {Maybe Text
message :: Maybe Text
$sel:message:Diagnostics' :: Diagnostics -> Maybe Text
message} -> Maybe Text
message) (\s :: Diagnostics
s@Diagnostics' {} Maybe Text
a -> Diagnostics
s {$sel:message:Diagnostics' :: Maybe Text
message = Maybe Text
a} :: Diagnostics)

instance Core.FromJSON Diagnostics where
  parseJSON :: Value -> Parser Diagnostics
parseJSON =
    String
-> (Object -> Parser Diagnostics) -> Value -> Parser Diagnostics
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Diagnostics"
      ( \Object
x ->
          Maybe Text
-> Maybe LifecycleErrorCode
-> Maybe Text
-> Maybe Text
-> Diagnostics
Diagnostics'
            (Maybe Text
 -> Maybe LifecycleErrorCode
 -> Maybe Text
 -> Maybe Text
 -> Diagnostics)
-> Parser (Maybe Text)
-> Parser
     (Maybe LifecycleErrorCode
      -> Maybe Text -> Maybe Text -> Diagnostics)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"logTail")
            Parser
  (Maybe LifecycleErrorCode
   -> Maybe Text -> Maybe Text -> Diagnostics)
-> Parser (Maybe LifecycleErrorCode)
-> Parser (Maybe Text -> Maybe Text -> Diagnostics)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe LifecycleErrorCode)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"errorCode")
            Parser (Maybe Text -> Maybe Text -> Diagnostics)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Diagnostics)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"scriptName")
            Parser (Maybe Text -> Diagnostics)
-> Parser (Maybe Text) -> Parser Diagnostics
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"message")
      )

instance Prelude.Hashable Diagnostics

instance Prelude.NFData Diagnostics