Skip to content

Commit

Permalink
fix: Make sure deferred functions are actually called
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan committed Sep 19, 2024
1 parent 3bfe17c commit 76a88d1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/influx_tools/parquet/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (cmd *Command) Run(args []string) (err error) {
if err := exp.open(ctx); err != nil {
return fmt.Errorf("opening exporter failed: %w", err)
}
defer internal_errors.Capture(&err, exp.close)
defer internal_errors.Capture(&err, exp.close)()

exp.printPlan(cmd.Stderr)

Expand Down
6 changes: 4 additions & 2 deletions cmd/influx_tools/parquet/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ func (e *exporter) exportMeasurement(ctx context.Context, shard *tsdb.Shard, mea
if err != nil {
return fmt.Errorf("creating file %q failed: %w", filename, err)
}
defer internal_errors.Capture(&err, file.Close)

writer, err := pqarrow.NewFileWriter(
schema,
Expand All @@ -428,9 +427,12 @@ func (e *exporter) exportMeasurement(ctx context.Context, shard *tsdb.Shard, mea
pqarrow.NewArrowWriterProperties(pqarrow.WithCoerceTimestamps(arrow.Nanosecond)),
)
if err != nil {
if err := file.Close(); err != nil {
e.logger.Errorf("closing file failed: %v", err)
}
return fmt.Errorf("creating parquet writer for file %q failed: %w", filename, err)
}
defer internal_errors.Capture(&err, writer.Close)
defer internal_errors.Capture(&err, writer.Close)()

// Prepare the record builder
builder := array.NewRecordBuilder(memory.DefaultAllocator, schema)
Expand Down
2 changes: 1 addition & 1 deletion cmd/influx_tools/parquet/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *schemaCreator) extractSchema(ctx context.Context) (err error) {
if err != nil {
return fmt.Errorf("getting series cursor failed: %w", err)
}
defer errors.Capture(&err, seriesCursor.Close)
defer errors.Capture(&err, seriesCursor.Close)()

for {
cur, err := seriesCursor.Next()
Expand Down

0 comments on commit 76a88d1

Please sign in to comment.