Skip to content

Commit 154250c

Browse files
committed
a couple minor fixes in tests, docs and code
1 parent bea4c7e commit 154250c

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

XakeLibTests/ActionTests.fs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ let ``try finally fail``() =
289289
let ``exception handling with 'try with'``() =
290290

291291
let errorlist = makeStringList()
292-
let note = errorlist.Add
293292
let anote txt = action {
294293
do errorlist.Add txt
295294
}
@@ -304,8 +303,7 @@ let ``exception handling with 'try with'``() =
304303
do! anote "try"
305304
failwith "Ouch"
306305
with e ->
307-
printfn "Finally executed"
308-
do note e.Message
306+
do! anote e.Message
309307

310308
do! anote "4"
311309
})

core/Action.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ module Action =
3939
} |> Action
4040

4141
let tryFinallyF body comp = // (body:Action<'a,'b>) -> (comp: unit -> unit) -> Action<'a,'b> =
42-
fun (r, a) -> async {
42+
fun x -> async {
4343
try
44-
return! runAction body (r,a)
44+
return! runAction body x
4545
finally
4646
do comp()
4747
} |> Action

docs/implnotes.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ Error handling assumes the following system behavior:
3131

3232
### Implemented ideas
3333

34+
#### try/with/finally exception handling
35+
`action` computation expression supports try/with and try/finally blocks.
36+
37+
```fsharp
38+
action {
39+
do! log "before try"
40+
41+
try
42+
try
43+
do! log "Body executed"
44+
failwith "Ouch"
45+
with e ->
46+
do! log "Exception: %s" e.Message
47+
finally
48+
printfn "Error!"
49+
}
50+
```
51+
52+
> actions (with do! notation) are allowed in `with` block but aren't in `finally` block. This is limitation of F#'s computation expressions.
53+
3454
#### WhenError function
3555
Intercepts errors (exceptions) and allows to define a custom handler.
3656
```
@@ -49,10 +69,6 @@ do! _system [shellcmd] "dir" |> FailWhen ((<>) 0) "Failed to list files in folde
4969
do! _system [shellcmd] "dir" |> CheckErrorLevel
5070
```
5171

52-
#### try/with/finally exception handling
53-
`action` computation expression supports try/with and try/finally blocks. In most cases these constructs are more
54-
elegant than using WhenError.
55-
5672
### Other ideas
5773

5874
// or even that:
@@ -66,8 +82,6 @@ do! _system [fail_on_error; shellcmd; startin "./bin"] "dir"
6682
// where shellcmd and fail_on_error are functions
6783
```
6884
69-
Let action be provided as finally argument.
70-
7185
### Ideas
7286
Implemented IgnoreErrors.
7387

docs/overview.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
44

55
- [The first script](#the-first-script)
6-
- [Boostrapping Xake.Core](#boostrapping-xakecore)
6+
- [Bootstrapping Xake.Core](#bootstrapping-xakecore)
77
- [So what?](#so-what)
88
- [Dependencies tracking](#dependencies-tracking)
99
- [Running multiple rules in parallel](#running-multiple-rules-in-parallel)
@@ -18,6 +18,7 @@
1818
- [wantOverride](#wantoverride)
1919
- [action computation](#action-computation)
2020
- [Tasks, `do!` notation](#tasks-do-notation)
21+
- [Exception handling](#exception-handling)
2122
- [need](#need)
2223
- [Filesets](#filesets)
2324
- [Other functions](#other-functions)
@@ -62,7 +63,7 @@ Here are we doing the following steps:
6263
1. specify the default target ("main") requires "hw.exe" target
6364
1. define the rule for "hw.exe" target
6465

65-
### Boostrapping Xake.Core
66+
### Bootstrapping Xake.Core
6667

6768
The steps above assumes you've downloaded xake core assembly to .tools folder.
6869
The next script demonstrates how to create the build script that does not require any installation steps:
@@ -290,11 +291,11 @@ If the task (action) returns a value which you do not need use Action.Ignore:
290291
```fsharp
291292
action {
292293
do! system "ls" [] |> Action.Ignore
293-
if error_code <> 0 then failwith...
294294
}
295295
```
296296

297297
### Exception handling
298+
298299
`action` block allows to handle exceptions with idiomatic try/with and try/finally blocks.
299300
```fsharp
300301
phony "main" (action {
@@ -304,14 +305,13 @@ If the task (action) returns a value which you do not need use Action.Ignore:
304305
do! trace Level.Info "try"
305306
failwith "Ouch"
306307
with e ->
307-
printfn "Error '%s' occured" e.Message
308+
do! trace Level.Error "Error '%s' occured" e.Message
308309
finally
309310
printfn "Finally executed"
310-
311311
printfn "execution continues after try blocks"
312312
})
313313
```
314-
Notice `trace` function just like any other actions cannot be used inside `with` and `finally` blocks due to language limitations.
314+
Notice `trace` function just like any other actions (do! notation) cannot be used in `finally` blocks due to language limitations.
315315

316316
`WhenError` function is another option to handle errors.
317317
```fsharp

0 commit comments

Comments
 (0)