Add more context aware error for policy parsing errors (#8726)

In existing functionality we simply return a generic
error such as "MalformedPolicy" which indicates just
a generic string "invalid resource" which is not very
meaningful when there might be multiple types of errors
during policy parsing. This PR ensures that we send
these errors back to client to indicate the actual
error, brings in two concrete types such as

 - iampolicy.Error
 - policy.Error

Refer #8202
This commit is contained in:
Harshavardhana authored and GitHub committed 2020-01-03 11:28:52 -08:00
1 parent 84e55e2e6f
commit 6695fd6a61
23 files changed
+141 -67

No files matched your search

+2 -3
View File
@@ -18,7 +18,6 @@ package policy
import (
"encoding/json"
"fmt"
)
// Effect - policy statement effect Allow or Deny.
@@ -54,7 +53,7 @@ func (effect Effect) IsValid() bool {
// MarshalJSON - encodes Effect to JSON data.
func (effect Effect) MarshalJSON() ([]byte, error) {
if !effect.IsValid() {
return nil, fmt.Errorf("invalid effect '%v'", effect)
return nil, Errorf("invalid effect '%v'", effect)
}
return json.Marshal(string(effect))
@@ -69,7 +68,7 @@ func (effect *Effect) UnmarshalJSON(data []byte) error {
e := Effect(s)
if !e.IsValid() {
return fmt.Errorf("invalid effect '%v'", s)
return Errorf("invalid effect '%v'", s)
}
*effect = e