hookdeck / hookdeck-cli

Alternative to ngrok for localhost asynchronous web development (e.g. webhooks). No account required.
https://hookdeck.com?ref=github-hookdeck-cli
Apache License 2.0
260 stars 9 forks source link

refactor: Use Go SDK to make requests to Hookdeck API #67

Closed alexluong closed 4 months ago

leggetter commented 4 months ago

@alexluong - trying this locally and getting an error on this command where I'm passing the source name of inbound as an argument:

./hookdeck-cli listen 3000 inbound                                                                                                                                                                                                  ~/hookdeck/git/hookdeck-go-sdk
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x8 pc=0x1030678c8]

goroutine 1 [running]:
github.com/hookdeck/hookdeck-cli/pkg/listen.getConnections(0x1400019cbe0, 0x140000e2000, {0x0, 0x0})
        /Users/leggetter/hookdeck/git/hookdeck-go-sdk/pkg/listen/connection.go:28 +0xd8
github.com/hookdeck/hookdeck-cli/pkg/listen.Listen(0x1400013c2d0, {0x16d18b233, 0x7}, {0x0, 0x0}, {0x38?}, 0x103565a00)
        /Users/leggetter/hookdeck/git/hookdeck-go-sdk/pkg/listen/listen.go:54 +0xa4
github.com/hookdeck/hookdeck-cli/pkg/cmd.(*listenCmd).runListenCmd(0x14000120800, 0x0?, {0x14000120980, 0x16d18b22e?, 0x102e2cea0?})
        /Users/leggetter/hookdeck/git/hookdeck-go-sdk/pkg/cmd/listen.go:115 +0x184
github.com/spf13/cobra.(*Command).execute(0x1400019e848, {0x14000120940, 0x2, 0x2})
        /Users/leggetter/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:842 +0x568
github.com/spf13/cobra.(*Command).ExecuteC(0x10355fe20)
        /Users/leggetter/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950 +0x310
github.com/spf13/cobra.(*Command).Execute(...)
        /Users/leggetter/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
github.com/hookdeck/hookdeck-cli/pkg/cmd.Execute()
        /Users/leggetter/hookdeck/git/hookdeck-go-sdk/pkg/cmd/root.go:46 +0x2c
main.main()
        /Users/leggetter/hookdeck/git/hookdeck-go-sdk/main.go:21 +0x1c

You can see the sources I have available here:

$ ./hookdeck-cli listen 3000                                                                                                                                                                                                         
? Select a source  [Use arrows to move, type to filter]
> rate-limit-example
  shopify
  hookdeck-notifications
  inbound
  Create new source

Here's how the version 0.8.6 of the CLI behaves:

hookdeck listen 3000 inbound --log-level=debug                                                                                                                                                                                     

Dashboard
👉 Inspect and replay webhooks: https://dashboard.hookdeck.com?team_id=tm_ne5C5OtrqDga

inbound Source
🔌 Webhook URL: https://hkdk.events/IzHOdKAHBk41

Connections
cli forwarding to /webhook

⢿ Getting ready... [Wed, 01 May 2024 11:56:38 BST] DEBUG websocket.client.Run: Attempting to connect to Hookdeck
[Wed, 01 May 2024 11:56:38 BST] DEBUG websocket.Client.connect: Dialing websocket url=wss://ws.hookdeck.com
⣷ Getting ready... [Wed, 01 May 2024 11:56:38 BST] DEBUG websocket.client.connect: Connected!
> Ready! (^C to quit)
alexluong commented 4 months ago

Hi @leggetter, thanks for catching this issue. This happened because your source has a few different connections and some connections do not lead to a CLI destination. With the refactor, the data shape is a bit different so the way we check whether a destination is CLI or not led to the invalid memory address issue. I have updated the logic to account for this case.

Can you check and see if the CLI behaves as expected now?