From bf1244b74dc44cd359ddda4ced5a842841df08ce Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 7 Sep 2026 09:11:28 +0000 Subject: [PATCH] fix: exit non-zero when the SDK key is missing or initialization fails Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- app/Main.hs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index a440eae..ad61d6d 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -3,13 +3,14 @@ module Main where import Control.Concurrent (threadDelay) -import Control.Monad (forever) -import Data.Text (Text, pack) +import Data.Text (pack) import Data.Function ((&)) import qualified LaunchDarkly.Server as LD +import System.Exit (exitFailure) +import System.IO (hPutStrLn, stderr) import System.Timeout (timeout) -import Text.Printf (printf, hPrintf) +import Text.Printf (printf) import System.Environment (lookupEnv) import Data.Maybe (isJust) @@ -58,6 +59,9 @@ evaluateLoop client featureFlagKey context lastValue ciMode = do if ciMode then pure () else threadDelay (1 * 1_000_000) >> evaluateLoop client featureFlagKey context (Just value) ciMode evaluate :: Maybe String -> Maybe String -> Bool -> IO () +evaluate Nothing _ _ = do + hPutStrLn stderr "*** You must define LAUNCHDARKLY_SDK_KEY before running this script" + exitFailure evaluate (Just sdkKey) Nothing ciMode = do evaluate (Just sdkKey) (Just "sample-feature") ciMode evaluate (Just sdkKey) (Just featureFlagKey) ciMode = do -- Set up the evaluation context. This context should appear on your @@ -68,10 +72,11 @@ evaluate (Just sdkKey) (Just featureFlagKey) ciMode = do case initialized of Just True -> do - print "*** SDK successfully initialized!" + putStrLn "*** SDK successfully initialized!" evaluateLoop client featureFlagKey context Nothing ciMode - _notInitialized -> putStrLn "*** SDK failed to initialize. Please check your internet connection and SDK credential for any typo." -evaluate _ _ _ = putStrLn "*** You must define LAUNCHDARKLY_SDK_KEY and LAUNCHDARKLY_FLAG_KEY before running this script" + _notInitialized -> do + hPutStrLn stderr "*** SDK failed to initialize. Please check your internet connection and SDK credential for any typo." + exitFailure main :: IO () main = do