Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to? Catch missing credentials errors #242

Closed
ThisIsMissEm opened this issue Mar 11, 2014 · 9 comments
Closed

How to? Catch missing credentials errors #242

ThisIsMissEm opened this issue Mar 11, 2014 · 9 comments

Comments

@ThisIsMissEm
Copy link

I'm getting the following error when from the following code:

// code:
var AWS = new (require('aws-sdk'))();
var s3 = AWS.S3();

s3.listObjects({ Bucket: "my-bucket" }, function(err, objects){
  console.log(err, objects);
});
// Error:
Possibly unhandled TimeoutError: Missing credentials in config
    at ClientRequest.<anonymous> (/Users/micheil/Kano/repos/api-server/node_modules/aws-sdk/lib/http/node.js:51:34)
    at ClientRequest.g (events.js:180:16)
    at ClientRequest.EventEmitter.emit (events.js:92:17)
    at Socket.emitTimeout (http.js:1797:10)
    at Socket.g (events.js:180:16)
    at Socket.EventEmitter.emit (events.js:92:17)
    at Socket._onTimeout (net.js:326:8)
    at Timer.unrefTimeout [as ontimeout] (timers.js:412:13)

I know that this is because I've not supplied credentials (I'm using the environment provider), but I wish to catch this error and be able to show something more sensible back to the developer, and to also terminate the request which ends up triggering the listObjects call.

Seems to not come back via the standard (err, data) function signature.

Any ideas?

@lsegal
Copy link
Contributor

lsegal commented Mar 11, 2014

I can't seem to reproduce your behavior with the exception being thrown out of the call. I run the following:

delete process.env.AWS_ACCESS_KEY_ID;
delete process.env.AWS_SECRET_ACCESS_KEY;

var AWS = require('aws-sdk');
console.log(AWS.VERSION);
var s3 = new AWS.S3();

s3.listObjects({ Bucket: "my-bucket" }, function(err, objects){
  console.log(err, objects);
});

And I get this:

2.0.0-rc11
{ [TimeoutError: Could not load credentials from any providers]
  message: 'Could not load credentials from any providers',
  code: 'CredentialsError',
  time: Tue Mar 11 2014 10:55:23 GMT-0700 (PDT),
  originalError: 
   { message: 'Connection timed out after 1000ms',
     code: 'TimeoutError',
     time: Tue Mar 11 2014 10:55:23 GMT-0700 (PDT) },
  _willRetry: false } null

Note that it is being printed as part of the callback.

@ThisIsMissEm
Copy link
Author

Okay, so, it turns out that my web framework (Hapi) creates a Domain for the request/response lifecycle, this represents that:

https://gist.github.com/miksago/115c337327f64a3f086f

Essentially, the error gets printed twice.

@lsegal
Copy link
Contributor

lsegal commented Mar 13, 2014

It looks like we are jumping to the uncaughtError state of our request lifecycle when an error pops up in the complete event. I will look into this.

@lsegal lsegal added the bug label Mar 13, 2014
@lsegal lsegal closed this as completed in 566d346 Mar 19, 2014
@lsegal
Copy link
Contributor

lsegal commented Mar 19, 2014

Thanks for reporting this issue.

@ThisIsMissEm
Copy link
Author

@lsegal could you let me know when you ship a new release?

lsegal added a commit that referenced this issue Mar 26, 2014
lsegal added a commit that referenced this issue Apr 24, 2014
@danie11am
Copy link

I experience the same problem. I'm using aws-sdk 2.0.0-rc.17.

I know the error is due to missing credentials, and want to make sure it's caught if it ever happens. I found that a TimeoutError would be returned in callback-style in the first 2-3 times this happens, but in around the 3rd time, a CredentialsError is thrown that will crash the process.

// My codes
var ses = new aws.SES({
  apiVersion : '2010-12-01'
});
ses.sendEmail(email, function(err, receipt) {
  if (err) {
    logger.error("notifyImmediate(): ses.sendEmail failed. err: " + err);
    return callback(err);
  }
  ..
};

The error:

/..../node_modules/aws-sdk/lib/request.js:34
    throw e;
          ^
TimeoutError: Could not load credentials from any providers
    at ClientRequest.<anonymous> (/..../node_modules/aws-sdk/lib/http/node.js:51:34)
    at ClientRequest.g (events.js:180:16)
    at ClientRequest.EventEmitter.emit (events.js:92:17)
    at Socket.emitTimeout (http.js:1797:10)
    at Socket.g (events.js:180:16)
    at Socket.EventEmitter.emit (events.js:92:17)
    at Socket._onTimeout (net.js:327:8)
    at Timer.unrefTimeout [as ontimeout] (timers.js:412:13)

@lsegal
Copy link
Contributor

lsegal commented Jun 17, 2014

@danie11am I would recommend upgrading to the latest version of the SDK (rc20) as error handling has changed slightly to not throw these exceptions.

@danie11am
Copy link

I just tried rc20, it no longer has this problem. Error is returned via callback even after many tries. Thanks @lsegal!

@lock
Copy link

lock bot commented Sep 30, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants