// Retrieve returns the credentials value or error if no provider returned // without error. // // If a provider is found it will be cached and any calls to IsExpired() // will return the expired state of the cached provider. func (c *ChainProvider) Retrieve() (Value, error) { var errs []error for _, p := range c.Providers { creds, err := p.Retrieve() if err == nil { c.curr = p return creds, nil } errs = append(errs, err) } c.curr = nil var err error err = ErrNoValidProvidersFoundInChain if c.VerboseErrors { err = awserr.NewBatchError("NoCredentialProviders", "no valid providers in chain", errs) } return Value{}, err }
func TestChainProviderWithNoValidProviderWithVerboseEnabled(t *testing.T) { errs := []error{ awserr.New("FirstError", "first provider error", nil), awserr.New("SecondError", "second provider error", nil), } p := &ChainProvider{ VerboseErrors: true, Providers: []Provider{ &stubProvider{err: errs[0]}, &stubProvider{err: errs[1]}, }, } assert.True(t, p.IsExpired(), "Expect expired with no providers") _, err := p.Retrieve() assert.Equal(t, awserr.NewBatchError("NoCredentialProviders", "no valid providers in chain", errs), err, "Expect no providers error returned") }
func unmarshalInvalidChangeBatchError(r *request.Request, requestBody []byte) { resp := &invalidChangeBatchXMLErrorResponse{} err := xml.Unmarshal(requestBody, resp) if err != nil { r.Error = awserr.New("SerializationError", "failed to decode query XML error response", err) return } const errorCode = "InvalidChangeBatch" errors := []error{} for _, msg := range resp.Messages { errors = append(errors, awserr.New(errorCode, msg, nil)) } r.Error = awserr.NewRequestFailure( awserr.NewBatchError(errorCode, "ChangeBatch errors occurred", errors), r.HTTPResponse.StatusCode, r.RequestID, ) }
// OrigErr returns the invalid parameters as a awserr.BatchedErrors value func (e ErrInvalidParams) OrigErr() error { return awserr.NewBatchError( InvalidParameterErrCode, e.Message(), e.OrigErrs()) }