go-sdk
go-sdk copied to clipboard
Add nil-check validation in CreateStoreExecute
trafficstars
Description
The CreateStoreExecute method in client/client.go calls request.GetBody().Name without checking whether GetBody() returns nil, which can cause a panic.
Also there are other methods with the same issue - go through them and make sure any that need fixing is fixed.
Recommendation
Add validation to check if request.GetBody() is nil before accessing Name. If nil, return a FgaRequiredParamError with param "body" to provide a graceful error instead of a nil-dereference panic. Add tests to cover the scenarios that body is nil for all relevant methods
References
- PR: https://github.com/openfga/go-sdk/pull/233
- Comment: https://github.com/openfga/go-sdk/pull/233#discussion_r2359562337
- Requested by: @rhamzeh
Location
File: client/client.go
Lines: ~691-705 (CreateStoreExecute function)