Skip to content

Commit 07b6041

Browse files
authored
Fix Plugins infinite int stream sample (#1911)
Tested working in 0.104.0
1 parent 59fcd3b commit 07b6041

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

contributor-book/plugins.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,13 @@ Since `run()` also returns `PipelineData`, it is also possible for the plugin to
358358
two:
359359

360360
```rust
361-
fn run(..., input: PipelineData) -> Result<PipelineData, ShellError> {
362-
Ok(input.map(|value| {
361+
fn run(
362+
...,
363+
engine: &EngineInterface,
364+
call: &EvaluatedCall,
365+
input: PipelineData,
366+
) -> Result<PipelineData, ShellError> {
367+
input.map(|value| {
363368
let span = value.span();
364369
match value.as_int() {
365370
Ok(int) => Value::int(int * 2, span),
@@ -368,14 +373,24 @@ fn run(..., input: PipelineData) -> Result<PipelineData, ShellError> {
368373
// `Value::Error`.
369374
Err(err) => Value::error(err, span),
370375
}
371-
}))
376+
}, engine.signals()).map_err(|e|
377+
LabeledError::new(
378+
"Failed",
379+
).with_label(
380+
format!(
381+
"Failed; {}",
382+
e,
383+
),
384+
call.head,
385+
)
386+
)
372387
}
373388
```
374389

375390
Since the input and output are both streaming, this will work even on an infinite stream:
376391

377392
```nu
378-
$ generate 0 { |n| {out: $n, next: ($n + 1)} } | plugin
393+
$ generate { |n| {out: $n, next: ($n + 1)} } 0 | plugin
379394
0
380395
2
381396
4

0 commit comments

Comments
 (0)