From 03245abe186970992caec066a290dfadd04be7da Mon Sep 17 00:00:00 2001 From: Isaac Abraham Date: Tue, 28 Feb 2017 09:52:12 +0100 Subject: [PATCH] Improve error handling on SqlPackage. * If custom path to SQL Package is used, show that one if it is invalid. * If error occurs during SQL Package deployment, do not output error to stderr. --- src/app/FakeLib/Sql.DacPac.fs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/app/FakeLib/Sql.DacPac.fs b/src/app/FakeLib/Sql.DacPac.fs index ecd5b018fd4..339fefdb863 100644 --- a/src/app/FakeLib/Sql.DacPac.fs +++ b/src/app/FakeLib/Sql.DacPac.fs @@ -5,6 +5,8 @@ open Fake.EnvironmentHelper open Fake.ProcessHelper open System.IO open Fake.FileSystem +open System.Diagnostics +open System /// The type of action to execute. type DeployAction = @@ -95,15 +97,22 @@ let deployDb setParams = failwith "No SqlPackage.exe filename was given." if not (File.Exists args.SqlPackageToolPath) then - failwithf "Unable to find a valid instance of SqlPackage.exe. Paths checked were: %A." validPaths - - shellExec { - Program = args.SqlPackageToolPath - CommandLine = sprintf """/Action:%s /SourceFile:"%s" /TargetConnectionString:"%s" %s /p:BlockOnPossibleDataLoss=%b /p:DropObjectsNotInSource=%b /p:CommandTimeout=%d /p:CreateNewDatabase=%b %s %s""" action args.Source args.Destination outputPath args.BlockOnPossibleDataLoss args.DropObjectsNotInSource args.Timeout args.RecreateDb additionalParameters variables - WorkingDirectory = "" - Args = [] } - - |> function + let paths = + if validPaths |> List.contains args.SqlPackageToolPath then validPaths + else [ args.SqlPackageToolPath ] + failwithf "Unable to find a valid instance of SqlPackage.exe. Paths checked were: %A." paths + + let result = + ExecProcessWithLambdas + (fun psi -> + psi.Arguments <- sprintf """/Action:%s /SourceFile:"%s" /TargetConnectionString:"%s" %s /p:BlockOnPossibleDataLoss=%b /p:DropObjectsNotInSource=%b /p:CommandTimeout=%d /p:CreateNewDatabase=%b %s %s""" action args.Source args.Destination outputPath args.BlockOnPossibleDataLoss args.DropObjectsNotInSource args.Timeout args.RecreateDb additionalParameters variables + psi.FileName <- args.SqlPackageToolPath) + TimeSpan.MaxValue + true + (printfn "SqlPackage error: %s") + (printfn "%s") + + match result with | 0 -> () | _ -> failwith "Error executing DACPAC deployment. Please see output for error details."