Skip to content

Commit

Permalink
feat(transform): Recover from transform panics, return as error
Browse files Browse the repository at this point in the history
  • Loading branch information
dustmop authored and Arqu committed Nov 3, 2021
1 parent 6bae36d commit 924db4a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions transform/startf/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func NewStepRunner(target *dataset.Dataset, opts ...func(o *ExecOpts)) *StepRunn
}

// RunStep runs the single transform step using the dataset
func (r *StepRunner) RunStep(ctx context.Context, ds *dataset.Dataset, st *dataset.TransformStep) error {
func (r *StepRunner) RunStep(ctx context.Context, ds *dataset.Dataset, st *dataset.TransformStep) (err error) {
r.globals["load_dataset"] = starlark.NewBuiltin("load_dataset", r.loadDatasetFunc(ctx, ds))
r.globals["dataset"] = r.stards
r.globals["config"] = config(r.config)
Expand All @@ -207,6 +207,15 @@ func (r *StepRunner) RunStep(ctx context.Context, ds *dataset.Dataset, st *datas
return fmt.Errorf("starlark step Script must be a string. got %T", st.Script)
}

// Recover from errors.
defer func() {
if r := recover(); r != nil {
// Need to assign to the named return value from
// a recovery
err = fmt.Errorf("running transform: %w", r)
}
}()

// Parse, resolve, and compile a Starlark source file.
file, mod, err := starlark.SourceProgram(fmt.Sprintf("%s.star", st.Name), strings.NewReader(script), r.globals.Has)
if err != nil {
Expand All @@ -226,7 +235,7 @@ func (r *StepRunner) RunStep(ctx context.Context, ds *dataset.Dataset, st *datas
r.globals[key] = val
}

return nil
return
}

// TODO(b5): this needs to be finished
Expand Down

0 comments on commit 924db4a

Please sign in to comment.