From 28651cbaabd587f7c7dd34008506db68ac74dbe7 Mon Sep 17 00:00:00 2001 From: b5 Date: Thu, 28 Jan 2021 14:43:53 -0500 Subject: [PATCH] fix(transform): don't write to out streams when nil, use updated preview.Create new preview create lets us make previews & still read body data downstream --- go.mod | 2 +- lib/datasets.go | 8 ++++---- lib/transform.go | 6 ++++-- remote/browse.go | 2 +- transform/startf/exec_step.go | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 43cdd98c0..21d407b85 100644 --- a/go.mod +++ b/go.mod @@ -39,7 +39,7 @@ require ( github.com/olekukonko/tablewriter v0.0.4 github.com/pkg/errors v0.9.1 github.com/qri-io/dag v0.2.2-0.20201208212257-ae00241c4b48 - github.com/qri-io/dataset v0.2.1-0.20210126031523-f94fd2290107 + github.com/qri-io/dataset v0.2.1-0.20210128201320-3b1209495e96 github.com/qri-io/deepdiff v0.2.1-0.20200807143746-d02d9f531f5b github.com/qri-io/didmod v0.0.0-20201123165422-8b2e224c993a github.com/qri-io/doggos v0.1.0 diff --git a/lib/datasets.go b/lib/datasets.go index daa6324f9..341cbce6f 100644 --- a/lib/datasets.go +++ b/lib/datasets.go @@ -626,12 +626,12 @@ func (m *DatasetMethods) Save(p *SaveParams, res *dataset.Dataset) error { // allocate an ID for the transform, for now just log the events it produces runID := transform.NewRunID() m.inst.bus.SubscribeID(func(ctx context.Context, e event.Event) error { - when := time.Unix(e.Timestamp/1000000000, e.Timestamp%1000000000) - log.Infof("[%s] event %s: %s", when, e.Type, e.Payload) if e.Type == event.ETTransformPrint { if msg, ok := e.Payload.(event.TransformMessage); ok { - io.WriteString(scriptOut, msg.Msg) - io.WriteString(scriptOut, "\n") + if p.ScriptOutput != nil { + io.WriteString(scriptOut, msg.Msg) + io.WriteString(scriptOut, "\n") + } } } return nil diff --git a/lib/transform.go b/lib/transform.go index 5980b62ac..1e6555a5f 100644 --- a/lib/transform.go +++ b/lib/transform.go @@ -91,8 +91,10 @@ func (m *TransformMethods) Apply(p *ApplyParams, res *ApplyResult) error { log.Debugw("apply transform event", "type", e.Type, "payload", e.Payload) if e.Type == event.ETTransformPrint { if msg, ok := e.Payload.(event.TransformMessage); ok { - io.WriteString(p.ScriptOutput, msg.Msg) - io.WriteString(p.ScriptOutput, "\n") + if p.ScriptOutput != nil { + io.WriteString(p.ScriptOutput, msg.Msg) + io.WriteString(p.ScriptOutput, "\n") + } } } return nil diff --git a/remote/browse.go b/remote/browse.go index efb255292..794320da1 100644 --- a/remote/browse.go +++ b/remote/browse.go @@ -115,7 +115,7 @@ func (rp LocalPreviews) Preview(ctx context.Context, _, refStr string) (*dataset return nil, err } - return preview.CreatePreview(ctx, ds) + return preview.Create(ctx, ds) } // PreviewComponent gets a component for a reference & component name diff --git a/transform/startf/exec_step.go b/transform/startf/exec_step.go index 92216b094..d9fef8bc9 100644 --- a/transform/startf/exec_step.go +++ b/transform/startf/exec_step.go @@ -170,7 +170,7 @@ func (r *StepRunner) callTransformFunc(ctx context.Context, thread *starlark.Thr } if r.eventsCh != nil { - pview, err := preview.CreatePreview(ctx, ds) + pview, err := preview.Create(ctx, ds) if err != nil { return err }