Skip to content

Commit

Permalink
return checkable error in FindOffset if it is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
OS-M committed Jan 19, 2023
1 parent efe40bf commit 6955fc9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
25 changes: 18 additions & 7 deletions cmd/dev/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/proxima-one/streamdb-client-go/v2/pkg/connection"
"github.com/proxima-one/streamdb-client-go/v2/pkg/proximaclient"
"strconv"
"time"
)

Expand Down Expand Up @@ -60,12 +61,6 @@ func findOffset() {
}

func testStreamRegistryClient() {
streamRegistryClient = proximaclient.NewStreamRegistryClient(proximaclient.StreamRegistryClientOptions{
Endpoint: "https://streams.api.proxima.one",
RetryPolicy: connection.DefaultPolicy(),
DebugHttpOutput: false,
})

println("\n==================================== getStreamEndpoints() ====================================\n")
getStreamEndpoints()
println("\n==================================== findStream() ====================================\n")
Expand Down Expand Up @@ -130,8 +125,24 @@ func testStreamDbClientStreamWithBufferedReader() {
}

func main() {
streamRegistryClient = proximaclient.NewStreamRegistryClient(proximaclient.StreamRegistryClientOptions{
Endpoint: "https://streams.api.proxima.one",
RetryPolicy: connection.DefaultPolicy(),
DebugHttpOutput: false,
})

// testStreamRegistryClient()
// testStreamDbClientFetch()
// testStreamDbClientStream()
testStreamDbClientStreamWithBufferedReader()
// testStreamDbClientStreamWithBufferedReader()

t := time.Unix(time.Now().Unix()+10000, 0)
_, err := streamRegistryClient.FindOffset("proxima.eth-main.blocks.1_0", nil, &t)
if err != nil && err == proximaclient.OffsetNotFoundError() {
println("right")
}
_, err = strconv.ParseBool("gg")
if err != nil && err != proximaclient.OffsetNotFoundError() {
println("right")
}
}
3 changes: 3 additions & 0 deletions pkg/proximaclient/client_stream_registy_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ func (client *StreamRegistryClient) FindOffset(stream string, height *int64, tim
if err != nil {
return nil, err
}
if res.Id == "" {
return nil, OffsetNotFoundError()
}
return NewOffsetFromString(res.Id)
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/proximaclient/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package proximaclient

import "errors"

var offsetNotFoundError = errors.New("offset not found")

func OffsetNotFoundError() error {
return offsetNotFoundError
}

0 comments on commit 6955fc9

Please sign in to comment.