Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed exceptions not being logged #885

Merged
merged 1 commit into from
Jun 21, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()