Skip to content

Commit 3494423

Browse files
committed
fix config check
1 parent 1d17f5a commit 3494423

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

‎internal/config/config.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ var ErrPluginExists = errors.New("a plugin with that name already exists")
160160
var ErrPluginNotFound = errors.New("no plugin found")
161161
var ErrPluginNoType = errors.New("plugin: field `process` or `wasm` required")
162162
var ErrPluginBothTypes = errors.New("plugin: `process` and `wasm` cannot both be defined")
163-
var ErrPluginProcessNoCmd = errors.New("plugin: missing process command")
163+
var ErrPluginProcessTooManyCmd = errors.New("plugin: only one of `cmd` or `go_package` is allowed for process plugin")
164+
var ErrPluginProcessNoCmd = errors.New("plugin: missing `cmd` or `go_package` for process plugin")
164165

165166
var ErrInvalidDatabase = errors.New("database must be managed or have a non-empty URI")
166167
var ErrManagedDatabaseNoProject = errors.New(`managed databases require a cloud project

‎internal/config/v_two.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ func v2ParseConfig(rd io.Reader) (Config, error) {
4848
if conf.Plugins[i].Process != nil && conf.Plugins[i].WASM != nil {
4949
return conf, ErrPluginBothTypes
5050
}
51-
if conf.Plugins[i].Process != nil {
52-
if conf.Plugins[i].Process.Cmd == "" {
51+
if r := conf.Plugins[i].Process; r != nil {
52+
switch {
53+
case r.Cmd != "" && r.GoPkg != "":
54+
return conf, ErrPluginProcessTooManyCmd
55+
default:
5356
return conf, ErrPluginProcessNoCmd
5457
}
5558
}

‎internal/ext/process/gen.go‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,21 @@ func (r *Runner) Invoke(ctx context.Context, method string, args any, reply any,
5656

5757
var cmd *exec.Cmd
5858
switch {
59-
case r.Cmd != "" && r.GoPkg == "":
59+
case r.Cmd != "":
6060
// Check if the output plugin exists
6161
path, err := exec.LookPath(r.Cmd)
6262
if err != nil {
6363
return fmt.Errorf("process: %s not found", r.Cmd)
6464
}
6565
cmd = exec.CommandContext(ctx, path, method)
66-
case r.Cmd == "" && r.GoPkg != "":
66+
case r.GoPkg != "":
6767
// Check if the go binary exists
6868
path, err := exec.LookPath("go")
6969
if err != nil {
7070
return fmt.Errorf("go binary required to run go package %s", r.GoPkg)
7171
}
7272
cmd = exec.CommandContext(ctx, path, method)
7373
cmd.Args = []string{"run", r.GoPkg}
74-
case r.Cmd != "" && r.GoPkg != "":
75-
return fmt.Errorf("only one of cmd or go_package is allowed")
76-
default:
77-
return fmt.Errorf("cmd and go_package cannot both be empty for process plugin")
7874
}
7975

8076
cmd.Stdin = bytes.NewReader(stdin)

0 commit comments

Comments
 (0)