diff --git a/internal/run/minimumViableSpec.go b/internal/run/minimumViableSpec.go index dc8a77b5..7fa2a3c0 100644 --- a/internal/run/minimumViableSpec.go +++ b/internal/run/minimumViableSpec.go @@ -26,12 +26,19 @@ func (w *Workflow) retryWithMinimumViableSpec(ctx context.Context, parentStep *w substep := parentStep.NewSubstep("Retrying with minimum viable document") source := w.workflow.Sources[sourceID] - source.Transformations = append(source.Transformations, workflow.Transformation{ - FilterOperations: &workflow.FilterOperationsOptions{ - Operations: strings.Join(invalidOperations, ","), - Exclude: pointer.ToBool(true), - }, - }) + if len(invalidOperations) > 0 { + source.Transformations = append(source.Transformations, workflow.Transformation{ + FilterOperations: &workflow.FilterOperationsOptions{ + Operations: strings.Join(invalidOperations, ","), + Exclude: pointer.ToBool(true), + }, + }) + } else { + // Sometimes the document has invalid, unused sections + source.Transformations = append(source.Transformations, workflow.Transformation{ + RemoveUnused: pointer.ToBool(true), + }) + } w.workflow.Sources[sourceID] = source sourcePath, sourceRes, err := w.RunSource(ctx, substep, sourceID, targetID) diff --git a/internal/run/transform.go b/internal/run/transform.go index 534a7bb9..7fc842b7 100644 --- a/internal/run/transform.go +++ b/internal/run/transform.go @@ -47,20 +47,20 @@ func (t Transform) Do(ctx context.Context, inputPath string) (string, error) { return "", err } - var out bytes.Buffer + var out *bytes.Buffer for _, transformation := range t.source.Transformations { - out = bytes.Buffer{} + out = &bytes.Buffer{} if transformation.Cleanup != nil { transformStep.NewSubstep("Cleaning up document") - if err := transform.CleanupFromReader(ctx, in, inputPath, &out, yamlOut); err != nil { + if err := transform.CleanupFromReader(ctx, in, inputPath, out, yamlOut); err != nil { return "", err } } else if transformation.RemoveUnused != nil { transformStep.NewSubstep("Removing unused nodes") - if err := transform.RemoveUnusedFromReader(ctx, in, inputPath, &out, yamlOut); err != nil { + if err := transform.RemoveUnusedFromReader(ctx, in, inputPath, out, yamlOut); err != nil { return "", err } } else if transformation.FilterOperations != nil { @@ -78,12 +78,12 @@ func (t Transform) Do(ctx context.Context, inputPath string) (string, error) { } transformStep.NewSubstep(fmt.Sprintf("Filtering %s %d operations", inOutString, len(operations))) - if err := transform.FilterOperationsFromReader(ctx, in, inputPath, operations, include, &out, yamlOut); err != nil { + if err := transform.FilterOperationsFromReader(ctx, in, inputPath, operations, include, out, yamlOut); err != nil { return "", err } } - in = &out + in = bytes.NewReader(out.Bytes()) } outFile, err := os.Create(outputPath) @@ -91,7 +91,7 @@ func (t Transform) Do(ctx context.Context, inputPath string) (string, error) { if err != nil { return "", err } - if _, err := io.Copy(outFile, &out); err != nil { + if _, err := io.Copy(outFile, out); err != nil { return "", err } diff --git a/prompts/sources.go b/prompts/sources.go index 46207357..1368e9ba 100644 --- a/prompts/sources.go +++ b/prompts/sources.go @@ -400,8 +400,6 @@ func PromptForNewSource(currentWorkflow *workflow.Workflow) (string, *workflow.S return "", nil, err } - println("FILE LOCATION: " + fileLocation) - document, err := formatDocument(fileLocation, authHeader, false) if err != nil { return "", nil, err