github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/structs/tryerr_doc.yaml (about) 1 - DocumentID: tryerr 2 Title: >+ 3 `tryerr` 4 CategoryID: commands 5 Summary: >- 6 Handles errors inside a block of code 7 Description: |- 8 `tryerr` forces a different execution behavior where a failed process at the end 9 of a pipeline will cause the block to terminate regardless of any functions that 10 might follow. 11 12 It's usage is similar to try blocks in other languages (eg Java) but a closer 13 functional example would be `set -e` in Bash. 14 15 To maintain concurrency within the pipeline, `tryerr` will only check the last 16 function in any given pipeline (ie series of functions joined via `|`, `->`, or 17 similar operators). If you need the entire pipeline checked then use `trypipe`. 18 Usage: |- 19 ``` 20 tryerr { code-block } -> <stdout> 21 22 <stdin> -> tryerr { -> code-block } -> <stdout> 23 ``` 24 Examples: |- 25 ``` 26 tryerr { 27 out "Hello, World!" -> grep: "non-existent string" 28 out "This command will be ignored" 29 } 30 ``` 31 Flags: 32 Detail: |- 33 A failure is determined by: 34 35 * Any process that returns a non-zero exit number 36 * Any process that returns more output via STDERR than it does via STDOUT 37 38 You can see which run mode your functions are executing under via the `fid-list` 39 command. 40 Synonyms: 41 Related: 42 - unsafe 43 - try 44 - trypipe 45 - trypipeerr 46 - catch 47 - runmode 48 - fid-list 49 - if 50 - switch 51 - schedulers 52 53 54 55 - DocumentID: trypipeerr 56 Title: >+ 57 `trypipeerr` 58 CategoryID: commands 59 Summary: >- 60 Checks state of each function in a pipeline and exits block on error 61 Description: |- 62 `trypipeerr` checks the state of each function and exits the block if any of them 63 fail. Where `trypipeerr` differs from regular `tryerr` blocks is `trypipeerr` will 64 check every process along the pipeline as well as the terminating function (which 65 `tryerr` only validates against). The downside to this is that piped functions can 66 no longer run in parallel. 67 Usage: |- 68 ``` 69 trypipeerr { code-block } -> <stdout> 70 71 <stdin> -> trypipeerr { -> code-block } -> <stdout> 72 ``` 73 Examples: |- 74 ``` 75 trypipeerr { 76 out "Hello, World!" -> grep: "non-existent string" -> cat 77 out "This command will be ignored" 78 } 79 ``` 80 81 Formated pager (`less`) where the pager isn't called if the formatter (`pretty`) fails (eg input isn't valid JSON): 82 83 ``` 84 func pless { 85 -> trypipeerr { -> pretty -> less } 86 } 87 ``` 88 Flags: 89 Detail: |- 90 A failure is determined by: 91 92 * Any process that returns a non-zero exit number 93 * Any process that returns more output via STDERR than it does via STDOUT 94 95 You can see which run mode your functions are executing under via the `fid-list` 96 command. 97 Synonyms: 98 Related: 99 - unsafe 100 - try 101 - tryerr 102 - trypipe 103 - catch 104 - runmode 105 - fid-list 106 - if 107 - switch 108 - schedulers