Skip to content

Commit

Permalink
fixed exceptions not being logged
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Taggart committed Jun 20, 2015
1 parent 36ea71b commit 0d86d20
Showing 1 changed file with 48 additions and 44 deletions.
92 changes: 48 additions & 44 deletions src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -250,54 +250,58 @@ let push (results : ArgParseResults<_>) =
?endPoint = results.TryGetResult <@ PushArgs.EndPoint @>,
?apiKey = results.TryGetResult <@ PushArgs.ApiKey @>)

try
let main() =
use consoleTrace = Logging.event.Publish |> Observable.subscribe Logging.traceToConsole
use fileTrace =
match logFile with
| Some lf -> setLogFile lf
| None -> null
let parser = UnionArgParser.Create<Command>()
let results =
parser.Parse(inputs = args,
ignoreMissing = true,
ignoreUnrecognized = true,
raiseOnUsage = false)

match results.GetAllResults() with
| [ command ] ->
let handler =
match command with
| Add -> processCommand add
| Config -> processWithValidation validateConfig config
| ConvertFromNuget -> processCommand convert
| FindRefs -> processCommand findRefs
| Init -> processCommand init
| AutoRestore -> processWithValidation validateAutoRestore autoRestore
| Install -> processCommand install
| Outdated -> processCommand outdated
| Remove -> processCommand remove
| Restore -> processCommand restore
| Simplify -> processCommand simplify
| Update -> processCommand update
| FindPackages -> processCommand findPackages
| FindPackageVersions -> processCommand findPackageVersions
| ShowInstalledPackages -> processCommand showInstalledPackages
| Pack -> processCommand pack
| Push -> processCommand push

let args = args.[1..]

handler command args
| [] ->
try
let parser = UnionArgParser.Create<Command>()
let results =
parser.Parse(inputs = args,
ignoreMissing = true,
ignoreUnrecognized = true,
raiseOnUsage = false)

match results.GetAllResults() with
| [ command ] ->
let handler =
match command with
| Add -> processCommand add
| Config -> processWithValidation validateConfig config
| ConvertFromNuget -> processCommand convert
| FindRefs -> processCommand findRefs
| Init -> processCommand init
| AutoRestore -> processWithValidation validateAutoRestore autoRestore
| Install -> processCommand install
| Outdated -> processCommand outdated
| Remove -> processCommand remove
| Restore -> processCommand restore
| Simplify -> processCommand simplify
| Update -> processCommand update
| FindPackages -> processCommand findPackages
| FindPackageVersions -> processCommand findPackageVersions
| ShowInstalledPackages -> processCommand showInstalledPackages
| Pack -> processCommand pack
| Push -> processCommand push

let args = args.[1..]

handler command args
| [] ->
Environment.ExitCode <- 1
traceError "Command was:"
traceError (" " + String.Join(" ",Environment.GetCommandLineArgs()))
parser.Usage("available commands:") |> traceError
| _ -> failwith "expected only one command"
with
| exn when not (exn :? System.NullReferenceException) ->
Environment.ExitCode <- 1
traceError "Command was:"
traceError (" " + String.Join(" ",Environment.GetCommandLineArgs()))
parser.Usage("available commands:") |> traceError
| _ -> failwith "expected only one command"
with
| exn when not (exn :? System.NullReferenceException) ->
Environment.ExitCode <- 1
traceErrorfn "Paket failed with:%s\t%s" Environment.NewLine exn.Message

if verbose then
traceErrorfn "StackTrace:%s %s" Environment.NewLine exn.StackTrace
traceErrorfn "Paket failed with:%s\t%s" Environment.NewLine exn.Message

if verbose then
traceErrorfn "StackTrace:%s %s" Environment.NewLine exn.StackTrace

main()

0 comments on commit 0d86d20

Please sign in to comment.