diff --git a/src/Semantic/CLI.hs b/src/Semantic/CLI.hs index 730c8b32f..b82e1f600 100644 --- a/src/Semantic/CLI.hs +++ b/src/Semantic/CLI.hs @@ -6,6 +6,7 @@ module Semantic.CLI , Parse.runParse ) where +import Control.Exception as Exc (displayException) import Data.File import Data.Language (ensureLanguage, languageForFilePath) import Data.List (intercalate, uncons) @@ -24,12 +25,17 @@ import qualified Semantic.Task as Task import Semantic.Task.Files import qualified Semantic.Telemetry.Log as Log import Semantic.Version +import System.Exit (die) import System.FilePath import Serializing.Format hiding (Options) import Text.Read main :: IO () -main = customExecParser (prefs showHelpOnEmpty) arguments >>= uncurry Task.runTaskWithOptions +main = do + (options, task) <- customExecParser (prefs showHelpOnEmpty) arguments + res <- Task.withOptions options $ \ config logger statter -> + Task.runTaskWithConfig config { configSHA = Just buildSHA } logger statter task + either (die . displayException) pure res -- | A parser for the application's command-line arguments. -- diff --git a/src/Semantic/Config.hs b/src/Semantic/Config.hs index 7e7cf1b9f..f0a3add28 100644 --- a/src/Semantic/Config.hs +++ b/src/Semantic/Config.hs @@ -23,7 +23,6 @@ import Semantic.Env import Semantic.Telemetry import qualified Semantic.Telemetry.Haystack as Haystack import qualified Semantic.Telemetry.Stat as Stat -import Semantic.Version import System.Environment import System.IO (hIsTerminalDevice, stdout) import System.Posix.Process @@ -43,6 +42,7 @@ data Config , configIsTerminal :: Bool -- ^ Whether a terminal is attached (set automaticaly at runtime). , configLogPrintSource :: Bool -- ^ Whether to print the source reference when logging errors (set automatically at runtime). , configLogFormatter :: LogFormatter -- ^ Log formatter to use (set automaticaly at runtime). + , configSHA :: Maybe String -- ^ Optional SHA to include in log messages. , configOptions :: Options -- ^ Options configurable via command line arguments. } @@ -84,6 +84,7 @@ defaultConfig options@Options{..} = do , configIsTerminal = isTerminal , configLogPrintSource = isTerminal , configLogFormatter = if isTerminal then terminalFormatter else logfmtFormatter + , configSHA = Nothing , configOptions = options } @@ -105,8 +106,9 @@ logOptionsFromConfig Config{..} = LogOptions False -> [ ("app", configAppName) , ("pid", show configProcessID) , ("hostname", configHostName) - , ("sha", buildSHA) - ] <> [("request_id", x) | x <- toList (optionsRequestID configOptions) ] + , ("sha", fromMaybe "development" configSHA) + ] + <> [("request_id", x) | x <- toList (optionsRequestID configOptions) ] _ -> [] diff --git a/test/Graphing/Calls/Spec.hs b/test/Graphing/Calls/Spec.hs index 89890be84..36b7bfa62 100644 --- a/test/Graphing/Calls/Spec.hs +++ b/test/Graphing/Calls/Spec.hs @@ -18,7 +18,7 @@ import Semantic.Config (defaultOptions) import Semantic.Graph import Semantic.IO -callGraphPythonProject paths = runTaskWithOptions defaultOptions $ do +callGraphPythonProject paths = runTask $ do let proxy = Proxy @'Language.Python let lang = Language.Python blobs <- catMaybes <$> traverse readBlobFromFile (flip File lang <$> paths)