Skip to content

Commit

Permalink
When plugin startup experiences panic, write known string to stdout s…
Browse files Browse the repository at this point in the history
…o plugin manager can intercept the "Unrecognized remote plugin message" and instead return the panic message. Closes #619
  • Loading branch information
kaidaguerre committed Aug 7, 2023
1 parent 93e7cc4 commit 1e90bd2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions plugin/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"net/http"
_ "net/http/pprof"
"os"
"fmt"

"github.com/hashicorp/go-hclog"
"github.com/turbot/go-kit/helpers"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc"
"github.com/turbot/steampipe-plugin-sdk/v5/logging"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/context_key"
Expand Down Expand Up @@ -44,7 +46,22 @@ passing callback functions to implement each of the plugin interface functions:
It is called from the main function of the plugin.
*/
const (
UnrecognizedRemotePluginMessage = "Unrecognized remote plugin message:"
UnrecognizedRemotePluginMessageSuffix = "\nThis usually means"
StartupPanicMessage = "Unhandled exception starting plugin: "
)

func Serve(opts *ServeOpts) {
defer func() {
if r := recover(); r != nil {
msg := fmt.Sprintf("%s%s", StartupPanicMessage, helpers.ToError(r).Error())
log.Println("[WARN]", msg)
// write to stdout so the plugin manager can extract the panic message
fmt.Println(msg)
}
}()

// create the logger
logger := setupLogger()

Expand Down

0 comments on commit 1e90bd2

Please sign in to comment.