Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.

Commit 3925192

Browse files
committed
Bug fixed
1 parent 26eaf5a commit 3925192

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

Bake.Actions/CreateDirectory.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ let createDirectoryTask (ctx: BakeActionContext) script (dir: string) =
1313
if not <| System.IO.Directory.Exists dir then
1414
System.IO.Directory.CreateDirectory dir
1515
|> ignore
16-
lock stdout (fun () -> printfn "CreateDirectory %s" dir)
1716
}
1817

1918
[<BakeAction>]

Bake.Core/Action.fs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ and BakeActionContext = {
2323
}
2424

2525
module Action =
26-
exception MethodIsNotAnException of string
2726
let getActionsFromAssembly (assembly: Assembly) =
2827
let toBakeAction (action: PropertyInfo) =
2928

@@ -68,7 +67,10 @@ module Action =
6867
, ctx
6968

7069
exception ActionNotFound of string
70+
exception ActionException of Script * BakeActionContext * exn
7171
let runAction ctx script =
7272
match ctx.actions |> Map.tryFind script.command with
7373
| None -> raise <| ActionNotFound script.command
74-
| Some action -> action.action ctx script
74+
| Some action ->
75+
try action.action ctx script
76+
with e -> raise <| ActionException (script, ctx, e)

Bake.Core/Task.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module Task =
2828
else false
2929
with _ -> true
3030

31-
31+
exception TaskException of Task * exn
3232
let run (task: Task) : Result<unit, exn> =
3333
if isDirty task then
3434
try
@@ -43,7 +43,7 @@ module Task =
4343
|> Seq.iter (fun x ->
4444
try System.IO.File.Delete x
4545
with _ -> ())
46-
Error e
46+
TaskException (task, e) |> Error
4747

4848
else Ok ()
4949

Bake/Program.fs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11

2+
open System
23
open Bake
34

5+
let processError fmt =
6+
Console.ForegroundColor <- ConsoleColor.Red
7+
Console.Beep ()
8+
Printf.kprintf (fun _ -> Console.ResetColor (); -1) fmt
9+
410
[<EntryPoint>]
511
let main args =
612
try
13+
try
14+
Console.SetWindowSize(90,40)
15+
with _ -> ()
716
let buildScriptFile =
817
match args with
918
| [||] ->
@@ -58,24 +67,12 @@ let main args =
5867

5968
0
6069
with
61-
| Parser.ParsingError e ->
62-
printfn "Parsing Error:%s" e
63-
-1
64-
| Action.ActionNotFound e ->
65-
printfn "Action Not Found:%s" e
66-
-1
67-
| Action.ActionUsageError e ->
68-
printfn "Action Usage Error:%s" e
69-
-1
70-
| e ->
71-
printfn "Error:%A" e
72-
-1
73-
74-
// Next: 实现以下Action
75-
// * If
76-
// * Equals $a $b
77-
// * Exists File $file
78-
// * Exists Directory $dir
79-
// * Not $Expression
80-
// * $SrcFiles Newer $DstFiles
70+
| Parser.ParsingError e -> processError "Parsing Error:%s" e
71+
| Action.ActionNotFound e -> processError "Action Not Found:%s" e
72+
| Action.ActionUsageError e -> processError "Action Usage Error:%s" e
73+
| Action.ActionException (script, ctx, e) ->
74+
processError "Action Error:%s\n\n%A\n\n%A\n\n%A" e.Message e script ctx
75+
| Task.TaskException (task, e) ->
76+
processError "Task Error:%s\n\n%A\n\n%A" e.Message e task
77+
| e -> processError "Error:%A" e
8178

0 commit comments

Comments
 (0)