File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -211,6 +211,44 @@ $result
211211# => ╰───┴───╯
212212```
213213
214+ When creating custom errors, loops have an advantage over pipelines because they don't fail evaluation.
215+
216+ Creating an error in a pipeline yields a pipeline evaluation error * and* the custom error:
217+
218+ ``` nu
219+ [0] | each { error make { msg: "Custom error" } | default '' }
220+ # => Error: nu::shell::eval_block_with_input
221+ # =>
222+ # => × Eval block failed with pipeline input
223+ # => ╭─[entry #20:1:2]
224+ # => 1 │ [0] | each { error make { msg: "Custom error" } | default '' }
225+ # => · ┬
226+ # => · ╰── source value
227+ # => ╰────
228+ # =>
229+ # => Error:
230+ # => × Custom error
231+ # => ╭─[entry #20:1:14]
232+ # => 1 │ [0] | each { error make { msg: "Custom error" } | default '' }
233+ # => · ─────┬────
234+ # => · ╰── originates from here
235+ # => ╰────
236+ ```
237+
238+ When using a loop, a ` for ` loop in this example, evaluation succeeds and only the created error occurs:
239+
240+ ``` nu
241+ for x in [0] { error make { msg: "Custom error" } }
242+ # => Error: nu::shell::error
243+ # =>
244+ # => × Custom error
245+ # => ╭─[entry #18:1:16]
246+ # => 1 │ for x in [0] { error make { msg: "Custom error" } }
247+ # => · ─────┬────
248+ # => · ╰── originates from here
249+ # => ╰────
250+ ```
251+
214252### ` for `
215253
216254[ ` for ` ] ( /commands/docs/for.html ) loops over a range or collection like a list or a table.
You can’t perform that action at this time.
0 commit comments