Skip to content

[Go] LookupPlugin panics when plugin does not exist #3354

@gregfurman

Description

@gregfurman

Describe the bug

genkit.LookupPlugin will panic if a plugin does not exist due to a type-assertion on a nil value:

panic: interface conversion: interface is nil, not genkit.Plugin

If this is expected behaviour, how should we be ascertaining if a plugin exists before registering? Since registering a plugin twice will (in some cases) also result in a panic.

To Reproduce

g, _ := genkit.Init(context.Background())
fooPlugin := genkit.LookupPlugin(g, "foo") // LookupPlugin should return nil, but panics instead
if fooPlugin == nil {
	fmt.Println("'foo' does not exist")
        return
}
fmt.Println("'foo' exists", fooPlugin.Name())

Expected behavior
A clear and concise description of what you expected to happen.

Relevant Code Snippet

genkit/go/genkit/genkit.go

Lines 764 to 771 in d7080f4

// LookupPlugin retrieves a registered plugin instance by its name.
// Plugins are registered during initialization via [WithPlugins].
// It returns the plugin instance as `Plugin` if found, or `nil` otherwise.
// The caller is responsible for type-asserting the returned value to the
// specific plugin type.
func LookupPlugin(g *Genkit, name string) Plugin {
return g.reg.LookupPlugin(name).(Plugin)
}

Runtime (please complete the following information):

  • OS: darwin/arm64

Go version

  • Genkit v0.6.2
  • Gov1.24.2

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggo

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions