Skip to content

Commit

Permalink
Improve exception message and handling of DocoptException
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed May 10, 2018
1 parent f5d82ec commit ffe5e4f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Fake.Core

exception DocoptException of string
with override x.ToString () = sprintf "DocoptException: %s" x.Data0
with override x.Message = sprintf "DocoptException: %s" x.Data0

namespace Fake.Core.CommandLineParsing

Expand Down
2 changes: 1 addition & 1 deletion src/app/Fake.Core.Target/Target.fs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ module Target =
| None -> fDefault singleTarget parallelJobs arguments
| Choice2Of2 e ->
// To ensure exit code.
failwithf "Usage error: %s\n%s" e.Message TargetCli.targetCli
raise <| exn (sprintf "Usage error: %s\n%s" e.Message TargetCli.targetCli, e)

/// Runs the command given on the command line or the given target when no target is given
let runOrDefault defaultTarget =
Expand Down
28 changes: 15 additions & 13 deletions src/app/Fake.netcore/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ type RunArguments = {
IsBuild : bool // Did the user call `fake build` or `fake run`?
}

let reportExn (verb:VerboseLevel) exn =
use logPaket =
// Required when 'silent' because we use paket API for error printing
if verb = Trace.Silent then
Paket.Logging.event.Publish
|> Observable.subscribe Paket.Logging.traceToConsole
else { new IDisposable with member __.Dispose () = () }
traceError "Script failed"
if Environment.GetEnvironmentVariable "FAKE_DETAILED_ERRORS" = "true" then
Paket.Logging.printErrorExt true true true exn
else Paket.Logging.printErrorExt verb.PrintVerbose verb.PrintVerbose false exn

let runOrBuild (args : RunArguments) =
if args.VerboseLevel.PrintVerbose then
Trace.log (sprintf "runOrBuild (%A)" args)
Expand Down Expand Up @@ -147,17 +159,7 @@ let runOrBuild (args : RunArguments) =
Fake.Profile.print true sw.Elapsed
with
| exn ->
use logPaket =
// Required when 'silent' because we use paket API for error printing
if args.VerboseLevel = Trace.Silent then
Paket.Logging.event.Publish
|> Observable.subscribe Paket.Logging.traceToConsole
else { new IDisposable with member __.Dispose () = () }
traceError "Script failed"
if Environment.GetEnvironmentVariable "FAKE_DETAILED_ERRORS" = "true" then
Paket.Logging.printErrorExt true true true exn
else Paket.Logging.printErrorExt args.VerboseLevel.PrintVerbose args.VerboseLevel.PrintVerbose false exn

reportExn args.VerboseLevel exn
//let isKnownException = exn :? FAKEException
//if not isKnownException then
// sendTeamCityError exn.Message
Expand Down Expand Up @@ -294,9 +296,9 @@ let main (args:string[]) =
parseAction rawResults
exitCode <- handleAction verbLevel results
with
| :? DocoptException as e ->
printfn "Usage error: %s" e.Message
| exn ->
printfn "%s" Cli.fakeUsage
reportExn VerboseLevel.Normal exn
exitCode <- 1
Console.OutputEncoding <- encoding
#if !NETSTANDARD1_6
Expand Down

0 comments on commit ffe5e4f

Please sign in to comment.