Skip to content

Error on compiling generated files that don't use the sql.all option #3

@jdaftari-confluent

Description

@jdaftari-confluent

Running the generator on files that do not use the plugin options, throws the following error on compiling

imported and not used: "database/sql/driver"

Tools like buf.build run all plugins on all the files defined in the work directory. This also includes files that do not use this plugin. This leads the generator to add the import path for database/sql/driver even when it is not used.

Here's a simple example

❯ cat proto/error.proto
syntax = "proto3";

package person;

option go_package = "github.com/test/foo/person";

message Error {
  string msg = 1;
}
❯ cat gen/go/proto/error_sql.go
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: proto/error.proto

package proto

import (
        driver "database/sql/driver"
        fmt "fmt"
        proto "github.com/gogo/protobuf/proto"
        math "math"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions