Skip to content

Commit

Permalink
Add downstream error to NewDatasource (#395)
Browse files Browse the repository at this point in the history
* add downstream error to newdatasource

* Spellcheck
  • Loading branch information
idastambuk authored and adamyeats committed Oct 15, 2024
1 parent 380fd13 commit b478970
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cspell.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"surql",
"surrealdb",
"typecheck",
"vals"
"vals",
"errorsource"
]
}
5 changes: 3 additions & 2 deletions pkg/plugin/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/grafana-labs/surrealdb-datasource/pkg/client"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
"github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource"
"github.com/grafana/grafana-plugin-sdk-go/experimental/slo"
"github.com/surrealdb/surrealdb.go"
)
Expand Down Expand Up @@ -46,14 +47,14 @@ func NewDatasource(ctx context.Context, dsiConfig backend.DataSourceInstanceSett

db, err := surrealdb.New(config.Endpoint)
if err != nil {
return nil, err
return nil, errorsource.DownstreamError(err, false)
}

client := client.Use(db)

_, err = client.Connect(&config)
if err != nil {
return nil, fmt.Errorf("unable to connect to database: %w", err)
return nil, errorsource.DownstreamError(fmt.Errorf("unable to connect to database: %w", err), false)
}

return slo.NewMetricsWrapper(NewDatasourceInstance(client, &config), dsiConfig), nil
Expand Down

0 comments on commit b478970

Please sign in to comment.