@@ -138,8 +138,10 @@ func ConvertJsonStringToObject(input string, object any) error {
138138 return nil
139139}
140140
141- // ConvertObjectType converts a given object into another object.
142- // The to object must be passed in by reference
141+ // ConvertObjectType converts a given object into another object type.
142+ // This is done by converting the object into a JSON string, then using the
143+ // JSON string to populate the parameters of a new object.
144+ // The "to" object must be passed in by reference
143145func ConvertObjectType (from any , to any ) error {
144146 fromString , err := ConvertObjectToJsonString (from )
145147 if err != nil {
@@ -158,6 +160,9 @@ func ConvertObjectType(from any, to any) error {
158160func RemoveParametersAndPopulateObject (parameters map [string ]string , config any ) error {
159161 from := ConvertStringMapToAny (parameters )
160162 err := ConvertObjectType (from , config )
163+ if err != nil && strings .Contains (err .Error (), "error calling MarshalJSON" ) {
164+ return identifyImproperlyFormattedParameter (from )
165+ }
161166
162167 for i := 0 ; i < reflect .TypeOf (config ).Elem ().NumField (); i ++ {
163168 name := reflect .TypeOf (config ).Elem ().Field (i ).Name
@@ -210,3 +215,20 @@ func MapCopy(oldMap map[string]string) map[string]string {
210215 }
211216 return newMap
212217}
218+
219+ // identifyImproperlyFormattedParameter is called if the JSON marshal fails to parse the parameter map.
220+ // It attempts to convert each individual parameter into a JSON string to identify the specific
221+ // parameter that is improperly formatted on the storage class. This allows us to provide a more
222+ // granular error message to the user.
223+ func identifyImproperlyFormattedParameter (parameters map [string ]any ) error {
224+ for key , value := range parameters {
225+ parameter := map [string ]any {
226+ key : value ,
227+ }
228+ _ , err := ConvertObjectToJsonString (parameter )
229+ if err != nil {
230+ return fmt .Errorf ("failed to parse parameter key=%s, value=%s with error=%s" , key , value , err )
231+ }
232+ }
233+ return fmt .Errorf ("failed to parse parameter JSON, but could not determine which parameter could not be parsed" )
234+ }
0 commit comments