Fix type getters #115

Merged
fyrchik merged 2 commits from aarifullin/frostfs-api-go:fix/apemanager_getters into master 2024-09-06 12:54:07 +00:00
Member
  • Add type instance check for nil to avoid panic by accessing fields.

Fixed for apemanager, rppclient and netmap

* Add type instance check for nil to avoid panic by accessing fields. Fixed for `apemanager`, `rppclient` and `netmap`
aarifullin added 1 commit 2024-09-06 08:42:03 +00:00
[#XX] apemanager: Fix type getters
Some checks failed
DCO action / DCO (pull_request) Failing after 56s
Tests and linters / Tests (pull_request) Successful in 56s
Tests and linters / Tests with -race (pull_request) Successful in 1m13s
Tests and linters / Lint (pull_request) Successful in 1m19s
6c2cd0f0c4
* Add type instance check for nil to avoid panic by
  accessing fields.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
aarifullin requested review from storage-core-committers 2024-09-06 08:42:11 +00:00
aarifullin requested review from storage-core-developers 2024-09-06 08:42:12 +00:00
aarifullin force-pushed fix/apemanager_getters from 6c2cd0f0c4 to 61323c388f 2024-09-06 08:42:32 +00:00 Compare
dstepanov-yadro approved these changes 2024-09-06 08:44:31 +00:00
Dismissed
fyrchik approved these changes 2024-09-06 08:45:23 +00:00
Dismissed
Owner

Speaking of gopatch and why it is useful, here are some other occurences (I have removed false positives)

@@
var name, receiver identifier
var x, typ, rt, sel expression
@@

func (receiver *rt) name() typ {
+if receiver == nil {
+   return nil
+}
    return x.sel
}
diff --git a/acl/types.go b/acl/types.go
index b42528b..3160e61 100644
--- a/acl/types.go
+++ b/acl/types.go
@@ -330,11 +330,19 @@ func (bt *BearerTokenBody) SetEACL(v *Table) {
 }
 
 func (t *APEOverride) GetTarget() *ape.ChainTarget {
+	if t == nil {
+		return nil
+	}
 	return t.target
+
 }
 
 func (t *APEOverride) GetChains() []*ape.Chain {
+	if t == nil {
+		return nil
+	}
 	return t.chains
+
 }
 
 func (t *APEOverride) SetTarget(v *ape.ChainTarget) {
diff --git a/ape/types.go b/ape/types.go
index 935a5ea..b34328d 100644
--- a/ape/types.go
+++ b/ape/types.go
@@ -53,7 +53,11 @@ func (c *Chain) SetKind(kind chainKind) {
 }
 
 func (c *Chain) GetKind() chainKind {
+	if c == nil {
+		return nil
+	}
 	return c.kind
+
 }
 
 type ChainRaw struct {
@@ -67,5 +71,9 @@ func (c *ChainRaw) SetRaw(raw []byte) {
 }
 
 func (c *ChainRaw) GetRaw() []byte {
+	if c == nil {
+		return nil
+	}
 	return c.Raw
+
 }
diff --git a/apemanager/types.go b/apemanager/types.go
index 21edf85..b36371d 100644
--- a/apemanager/types.go
+++ b/apemanager/types.go
@@ -16,7 +16,11 @@ func (r *AddChainRequest) SetBody(body *AddChainRequestBody) {
 }
 
 func (r *AddChainRequest) GetBody() *AddChainRequestBody {
+	if r == nil {
+		return nil
+	}
 	return r.body
+
 }
 
 type AddChainRequestBody struct {
@@ -30,7 +34,11 @@ func (rb *AddChainRequestBody) SetTarget(target *ape.ChainTarget) {
 }
 
 func (rb *AddChainRequestBody) GetTarget() *ape.ChainTarget {
+	if rb == nil {
+		return nil
+	}
 	return rb.target
+
 }
 
 func (rb *AddChainRequestBody) SetChain(chain *ape.Chain) {
@@ -38,7 +46,11 @@ func (rb *AddChainRequestBody) SetChain(chain *ape.Chain) {
 }
 
 func (rb *AddChainRequestBody) GetChain() *ape.Chain {
+	if rb == nil {
+		return nil
+	}
 	return rb.chain
+
 }
 
 type AddChainResponse struct {
@@ -52,7 +64,11 @@ func (r *AddChainResponse) SetBody(body *AddChainResponseBody) {
 }
 
 func (r *AddChainResponse) GetBody() *AddChainResponseBody {
+	if r == nil {
+		return nil
+	}
 	return r.body
+
 }
 
 type AddChainResponseBody struct {
@@ -64,7 +80,11 @@ func (rb *AddChainResponseBody) SetChainID(chainID []byte) {
 }
 
 func (rb *AddChainResponseBody) GetChainID() []byte {
+	if rb == nil {
+		return nil
+	}
 	return rb.chainID
+
 }
 
 type RemoveChainRequest struct {
@@ -78,7 +98,11 @@ func (r *RemoveChainRequest) SetBody(body *RemoveChainRequestBody) {
 }
 
 func (r *RemoveChainRequest) GetBody() *RemoveChainRequestBody {
+	if r == nil {
+		return nil
+	}
 	return r.body
+
 }
 
 type RemoveChainRequestBody struct {
@@ -92,7 +116,11 @@ func (rb *RemoveChainRequestBody) SetTarget(target *ape.ChainTarget) {
 }
 
 func (rb *RemoveChainRequestBody) GetTarget() *ape.ChainTarget {
+	if rb == nil {
+		return nil
+	}
 	return rb.target
+
 }
 
 func (rb *RemoveChainRequestBody) SetChainID(chainID []byte) {
@@ -100,7 +128,11 @@ func (rb *RemoveChainRequestBody) SetChainID(chainID []byte) {
 }
 
 func (rb *RemoveChainRequestBody) GetChainID() []byte {
+	if rb == nil {
+		return nil
+	}
 	return rb.chainID
+
 }
 
 type RemoveChainResponse struct {
@@ -116,7 +148,11 @@ func (r *RemoveChainResponse) SetBody(body *RemoveChainResponseBody) {
 }
 
 func (r *RemoveChainResponse) GetBody() *RemoveChainResponseBody {
+	if r == nil {
+		return nil
+	}
 	return r.body
+
 }
 
 type ListChainsRequest struct {
@@ -130,7 +166,11 @@ func (r *ListChainsRequest) SetBody(body *ListChainsRequestBody) {
 }
 
 func (r *ListChainsRequest) GetBody() *ListChainsRequestBody {
+	if r == nil {
+		return nil
+	}
 	return r.body
+
 }
 
 type ListChainsRequestBody struct {
@@ -142,7 +182,11 @@ func (rb *ListChainsRequestBody) SetTarget(target *ape.ChainTarget) {
 }
 
 func (rb *ListChainsRequestBody) GetTarget() *ape.ChainTarget {
+	if rb == nil {
+		return nil
+	}
 	return rb.target
+
 }
 
 type ListChainsResponse struct {
@@ -156,7 +200,11 @@ func (r *ListChainsResponse) SetBody(body *ListChainsResponseBody) {
 }
 
 func (r *ListChainsResponse) GetBody() *ListChainsResponseBody {
+	if r == nil {
+		return nil
+	}
 	return r.body
+
 }
 
 type ListChainsResponseBody struct {
@@ -170,5 +218,9 @@ func (r *ListChainsResponseBody) SetChains(chains []*ape.Chain) {
 }
 
 func (r *ListChainsResponseBody) GetChains() []*ape.Chain {
+	if r == nil {
+		return nil
+	}
 	return r.chains
+
 }
diff --git a/netmap/types.go b/netmap/types.go
index 1fcdc6e..0e84f35 100644
--- a/netmap/types.go
+++ b/netmap/types.go
@@ -335,7 +335,11 @@ func (p *PlacementPolicy) SetContainerBackupFactor(backupFactor uint32) {
 }
 
 func (p *PlacementPolicy) GetReplicas() []Replica {
+	if p == nil {
+		return nil
+	}
 	return p.replicas
+
 }
 
 func (p *PlacementPolicy) SetReplicas(replicas []Replica) {
Speaking of gopatch and why it is useful, here are some other occurences (I have removed false positives) ``` @@ var name, receiver identifier var x, typ, rt, sel expression @@ func (receiver *rt) name() typ { +if receiver == nil { + return nil +} return x.sel } ``` ```diff diff --git a/acl/types.go b/acl/types.go index b42528b..3160e61 100644 --- a/acl/types.go +++ b/acl/types.go @@ -330,11 +330,19 @@ func (bt *BearerTokenBody) SetEACL(v *Table) { } func (t *APEOverride) GetTarget() *ape.ChainTarget { + if t == nil { + return nil + } return t.target + } func (t *APEOverride) GetChains() []*ape.Chain { + if t == nil { + return nil + } return t.chains + } func (t *APEOverride) SetTarget(v *ape.ChainTarget) { diff --git a/ape/types.go b/ape/types.go index 935a5ea..b34328d 100644 --- a/ape/types.go +++ b/ape/types.go @@ -53,7 +53,11 @@ func (c *Chain) SetKind(kind chainKind) { } func (c *Chain) GetKind() chainKind { + if c == nil { + return nil + } return c.kind + } type ChainRaw struct { @@ -67,5 +71,9 @@ func (c *ChainRaw) SetRaw(raw []byte) { } func (c *ChainRaw) GetRaw() []byte { + if c == nil { + return nil + } return c.Raw + } diff --git a/apemanager/types.go b/apemanager/types.go index 21edf85..b36371d 100644 --- a/apemanager/types.go +++ b/apemanager/types.go @@ -16,7 +16,11 @@ func (r *AddChainRequest) SetBody(body *AddChainRequestBody) { } func (r *AddChainRequest) GetBody() *AddChainRequestBody { + if r == nil { + return nil + } return r.body + } type AddChainRequestBody struct { @@ -30,7 +34,11 @@ func (rb *AddChainRequestBody) SetTarget(target *ape.ChainTarget) { } func (rb *AddChainRequestBody) GetTarget() *ape.ChainTarget { + if rb == nil { + return nil + } return rb.target + } func (rb *AddChainRequestBody) SetChain(chain *ape.Chain) { @@ -38,7 +46,11 @@ func (rb *AddChainRequestBody) SetChain(chain *ape.Chain) { } func (rb *AddChainRequestBody) GetChain() *ape.Chain { + if rb == nil { + return nil + } return rb.chain + } type AddChainResponse struct { @@ -52,7 +64,11 @@ func (r *AddChainResponse) SetBody(body *AddChainResponseBody) { } func (r *AddChainResponse) GetBody() *AddChainResponseBody { + if r == nil { + return nil + } return r.body + } type AddChainResponseBody struct { @@ -64,7 +80,11 @@ func (rb *AddChainResponseBody) SetChainID(chainID []byte) { } func (rb *AddChainResponseBody) GetChainID() []byte { + if rb == nil { + return nil + } return rb.chainID + } type RemoveChainRequest struct { @@ -78,7 +98,11 @@ func (r *RemoveChainRequest) SetBody(body *RemoveChainRequestBody) { } func (r *RemoveChainRequest) GetBody() *RemoveChainRequestBody { + if r == nil { + return nil + } return r.body + } type RemoveChainRequestBody struct { @@ -92,7 +116,11 @@ func (rb *RemoveChainRequestBody) SetTarget(target *ape.ChainTarget) { } func (rb *RemoveChainRequestBody) GetTarget() *ape.ChainTarget { + if rb == nil { + return nil + } return rb.target + } func (rb *RemoveChainRequestBody) SetChainID(chainID []byte) { @@ -100,7 +128,11 @@ func (rb *RemoveChainRequestBody) SetChainID(chainID []byte) { } func (rb *RemoveChainRequestBody) GetChainID() []byte { + if rb == nil { + return nil + } return rb.chainID + } type RemoveChainResponse struct { @@ -116,7 +148,11 @@ func (r *RemoveChainResponse) SetBody(body *RemoveChainResponseBody) { } func (r *RemoveChainResponse) GetBody() *RemoveChainResponseBody { + if r == nil { + return nil + } return r.body + } type ListChainsRequest struct { @@ -130,7 +166,11 @@ func (r *ListChainsRequest) SetBody(body *ListChainsRequestBody) { } func (r *ListChainsRequest) GetBody() *ListChainsRequestBody { + if r == nil { + return nil + } return r.body + } type ListChainsRequestBody struct { @@ -142,7 +182,11 @@ func (rb *ListChainsRequestBody) SetTarget(target *ape.ChainTarget) { } func (rb *ListChainsRequestBody) GetTarget() *ape.ChainTarget { + if rb == nil { + return nil + } return rb.target + } type ListChainsResponse struct { @@ -156,7 +200,11 @@ func (r *ListChainsResponse) SetBody(body *ListChainsResponseBody) { } func (r *ListChainsResponse) GetBody() *ListChainsResponseBody { + if r == nil { + return nil + } return r.body + } type ListChainsResponseBody struct { @@ -170,5 +218,9 @@ func (r *ListChainsResponseBody) SetChains(chains []*ape.Chain) { } func (r *ListChainsResponseBody) GetChains() []*ape.Chain { + if r == nil { + return nil + } return r.chains + } diff --git a/netmap/types.go b/netmap/types.go index 1fcdc6e..0e84f35 100644 --- a/netmap/types.go +++ b/netmap/types.go @@ -335,7 +335,11 @@ func (p *PlacementPolicy) SetContainerBackupFactor(backupFactor uint32) { } func (p *PlacementPolicy) GetReplicas() []Replica { + if p == nil { + return nil + } return p.replicas + } func (p *PlacementPolicy) SetReplicas(replicas []Replica) { ```
aarifullin force-pushed fix/apemanager_getters from 61323c388f to 2ae34b5458 2024-09-06 09:14:28 +00:00 Compare
aarifullin dismissed dstepanov-yadro's review 2024-09-06 09:14:28 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

aarifullin dismissed fyrchik's review 2024-09-06 09:14:28 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

aarifullin changed title from apemanager: Fix type getters to Fix type getters 2024-09-06 09:14:47 +00:00
Author
Member

Speaking of gopatch and why it is useful, here are some other occurences (I have removed false positives)

Awesome. I have also fixed that for rpcclient and netmap to avoid unexpected panics in the future

> Speaking of gopatch and why it is useful, here are some other occurences (I have removed false positives) Awesome. I have also fixed that for `rpcclient` and `netmap` to avoid unexpected panics in the future
acid-ant approved these changes 2024-09-06 09:30:36 +00:00
achuprov approved these changes 2024-09-06 10:54:14 +00:00
fyrchik reviewed 2024-09-06 12:40:21 +00:00
@ -20,5 +20,9 @@ type Conn interface {
// Client should not be used after Close() call
// on the connection: behavior is undefined.
func (c *Client) Conn() io.Closer {
if c == nil {
Owner

This was the kind of false-positive I was referring to)

This was the kind of false-positive I was referring to)
Owner

c is not expected to be nil and we will panic on calling Close anyway, so I would revert this change.

`c` is not expected to be nil and we will panic on calling `Close` anyway, so I would revert this change.
Author
Member

Hm. That's right point. I reverted the commit for rpcclient

Hm. That's right point. I reverted the commit for rpcclient
aarifullin force-pushed fix/apemanager_getters from 2ae34b5458 to 5e82e8c776 2024-09-06 12:50:43 +00:00 Compare
aarifullin requested review from acid-ant 2024-09-06 12:51:14 +00:00
aarifullin requested review from achuprov 2024-09-06 12:51:15 +00:00
fyrchik merged commit 0484647aae into master 2024-09-06 12:54:07 +00:00
fyrchik referenced this pull request from a commit 2024-09-06 12:54:08 +00:00
fyrchik referenced this pull request from a commit 2024-09-06 12:54:08 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
5 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-api-go#115
No description provided.