github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/structs/try_doc.yaml (about) 1 - DocumentID: unsafe 2 Title: >+ 3 `unsafe` 4 CategoryID: commands 5 Summary: >- 6 Execute a block of code, always returning a zero exit number 7 Description: |- 8 `unsafe` is similar to normal execution except that the exit number for the 9 last function in the `unsafe` block is ignored. `unsafe` always returns `0`. 10 11 This is useful in any situations where you might want errors ignored. 12 Usage: |- 13 ``` 14 unsafe { code-block } -> <stdout> 15 16 <stdin> -> unsafe { -> code-block } -> <stdout> 17 ``` 18 Examples: |- 19 ``` 20 try { 21 unsafe { err "foobar" } 22 out "This message still displays because the error is inside an `unsafe` block" 23 } 24 ``` 25 Flags: 26 Detail: 27 Synonyms: 28 Related: 29 - try 30 - trypipe 31 - tryerr 32 - trypipeerr 33 - catch 34 - runmode 35 - fid-list 36 - if 37 - switch 38 - schedulers 39 40 41 - DocumentID: try 42 Title: >+ 43 `try` 44 CategoryID: commands 45 Summary: >- 46 Handles non-zero exits inside a block of code 47 Description: |- 48 `try` forces a different execution behavior where a failed process at the end 49 of a pipeline will cause the block to terminate regardless of any functions that 50 might follow. 51 52 It's usage is similar to try blocks in other languages (eg Java) but a closer 53 functional example would be `set -e` in Bash. 54 55 To maintain concurrency within the pipeline, `try` will only check the last 56 function in any given pipeline (ie series of functions joined via `|`, `->`, or 57 similar operators). If you need the entire pipeline checked then use `trypipe`. 58 Usage: |- 59 ``` 60 try { code-block } -> <stdout> 61 62 <stdin> -> try { -> code-block } -> <stdout> 63 ``` 64 Examples: |- 65 ``` 66 try { 67 out "Hello, World!" -> grep: "non-existent string" 68 out "This command will be ignored" 69 } 70 ``` 71 Flags: 72 Detail: |- 73 A failure is determined by: 74 75 * Any process that returns a non-zero exit number 76 77 You can see which run mode your functions are executing under via the `fid-list` 78 command. 79 Synonyms: 80 Related: 81 - unsafe 82 - trypipe 83 - tryerr 84 - trypipeerr 85 - catch 86 - runmode 87 - fid-list 88 - if 89 - switch 90 - schedulers 91 92 93 94 - DocumentID: trypipe 95 Title: >+ 96 `trypipe` 97 CategoryID: commands 98 Summary: >- 99 Checks for non-zero exits of each function in a pipeline 100 Description: |- 101 `trypipe` checks the state of each function and exits the block if any of them 102 fail. Where `trypipe` differs from regular `try` blocks is `trypipe` will check 103 every process along the pipeline as well as the terminating function (which 104 `try` only validates against). The downside to this is that piped functions can 105 no longer run in parallel. 106 Usage: |- 107 ``` 108 trypipe { code-block } -> <stdout> 109 110 <stdin> -> trypipe { -> code-block } -> <stdout> 111 ``` 112 Examples: |- 113 ``` 114 trypipe { 115 out "Hello, World!" -> grep: "non-existent string" -> cat 116 out "This command will be ignored" 117 } 118 ``` 119 120 Formated pager (`less`) where the pager isn't called if the formatter (`pretty`) fails (eg input isn't valid JSON): 121 122 ``` 123 func pless { 124 -> trypipe { -> pretty -> less } 125 } 126 ``` 127 Flags: 128 Detail: |- 129 A failure is determined by: 130 131 * Any process that returns a non-zero exit number 132 133 You can see which run mode your functions are executing under via the `fid-list` 134 command. 135 Synonyms: 136 Related: 137 - unsafe 138 - try 139 - tryerr 140 - trypipeerr 141 - catch 142 - runmode 143 - fid-list 144 - if 145 - switch 146 - schedulers 147 148 149 150 - DocumentID: catch 151 Title: >+ 152 `catch` 153 CategoryID: commands 154 Summary: >- 155 Handles the exception code raised by `try` or `trypipe` 156 Description: |- 157 `catch` is designed to be used in conjunction with `try` and `trypipe` as it 158 handles the exceptions raised by the aforementioned. 159 Usage: |- 160 ``` 161 [ try | trypipe ] { code-block } -> <stdout> 162 163 catch { code-block } -> <stdout> 164 165 !catch { code-block } -> <stdout> 166 ``` 167 Examples: |- 168 ``` 169 try { 170 out "Hello, World!" -> grep: "non-existent string" 171 out "This command will be ignored" 172 } 173 174 catch { 175 out "An error was caught" 176 } 177 178 !catch { 179 out "No errors were raised" 180 } 181 ``` 182 Flags: 183 Detail: |- 184 `catch` can be used with a bang prefix to check for a lack of errors. 185 186 `catch` forwards on the STDIN and exit number of the calling function. 187 Synonyms: 188 - catch 189 - "!catch" 190 Related: 191 - unsafe 192 - try 193 - trypipe 194 - tryerr 195 - trypipeerr 196 - runmode 197 - if 198 - switch 199 - schedulers 200 201 202 203 - DocumentID: runmode 204 Title: >+ 205 `runmode` 206 CategoryID: commands 207 Summary: >- 208 Alter the scheduler's behaviour at higher scoping level 209 Description: |- 210 Due to dynamic nature in which blocks are compiled on demand, traditional `try` 211 and `trypipe` blocks cannot affect the runtime behaviour of schedulers already 212 invoked (eg for function blocks and modules which `try` et al would sit inside). 213 To solve this we need an additional command that is executed by the compiler 214 prior to the block being executed which can define the runmode of the scheduler. 215 This is the purpose of `runmode`. 216 217 The caveat of being a compiler command rather than a builtin is that `runmode` 218 needs be the first command in a block. 219 Usage: |- 220 ``` 221 runmode try|trypipe function|module 222 ``` 223 Examples: |- 224 ``` 225 function hello { 226 # Short conversation, exit on error 227 228 runmode try function 229 230 read name "What is your name? " 231 out "Hello $name, pleased to meet you" 232 233 read mood "How are you feeling? " 234 out "I'm feeling $mood too" 235 } 236 ``` 237 Flags: 238 Detail: |- 239 `runmode`'s parameters are ordered: 240 241 ### 1st parameter 242 243 #### unsafe 244 245 Always return a zero exit number. 246 247 #### try 248 249 Checks only the last command in the pipeline for errors. However still allows 250 commands in a pipeline to run in parallel. 251 252 #### trypipe 253 254 Checks every command in the pipeline before executing the next. However this 255 blocks pipelines from running every command in parallel. 256 257 #### tryerr 258 259 Checks last command in the pipeline for errors (still allowing commands to run 260 in parallel) plus also checks if STDERR contains excessive output. 261 262 #### trypipeerr 263 264 Checks every command in the pipeline before executing the next (blocking 265 commands from running in parallel) plus also checks if STDERR contains 266 excessive output. 267 268 ### 2nd parameter 269 270 #### function 271 272 Sets the runmode for all blocks within the function when `runmode` is placed at 273 the start of the function. This includes privates, autocompletes, events, etc. 274 275 #### module 276 277 Sets the runmode for all blocks within that module when placed at the start of 278 the module. This include any functions, privates, autocompletes, events, etc 279 that are inside that module. They do not need a separate `runmode ... function` 280 if `runmode ... module` is set. 281 Synonyms: 282 Related: 283 - unsafe 284 - try 285 - trypipe 286 - tryerr 287 - trypipeerr 288 - catch 289 - read 290 - out 291 - schedulers 292 - pipeline 293 - fid-list 294 - function 295 - private 296 - autocomplete 297 - event