Skip to content

client.upload throws un unhandled error #481

@akras14

Description

@akras14

I believe there is a bug in:
https://github.com/pkgcloud/pkgcloud/blob/master/lib/pkgcloud/openstack/storage/client/files.js#L124

The following code is being called:

writableStream = this._request(uploadOptions);

which in turn calls:

https://github.com/pkgcloud/pkgcloud/blob/master/lib/pkgcloud/openstack/client.js#L192

Client.prototype._request = function (options, callback) {

  var self = this;
  if (!self._isAuthorized()) {
    self.emit('log::trace', 'Not-Authenticated, inlining Auth...');
    var proxyStream = through();
    proxyStream.pause();

    self.auth(function (err) {
      if (err) {
        self.emit('log::error', 'Error with inline authentication', err);
        return errs.handle(err, callback); // <--- PROBLEM
      }
//...

This creates a problem, since writableStream = this._request(uploadOptions); does not pass a callback.

The code for errs.handle is bellow:

exports.handle = function (error, callback, stream) {

  error = exports.create(error);

  if (typeof callback === 'function') {
    callback(error);
  }

  if (typeof callback !== 'function' || stream) {
    var emitter = stream || callback || new events.EventEmitter();
    process.nextTick(function () { emitter.emit('error', error); });
    return emitter;
  }
};

As you can see, errs.handle expects a callback or a stream. If neither is provided it creates a new events.EventEmitter() and emits error on it on a next tick.

Since that new event emitter does not have any error listeners Node 4 throws an error, that cannot be caught by implementations using your library.

A proposed solution is to modify openstack/storage/client/files.js as follows:

writableStream = this._request(uploadOptions, function(err){
  if(err){
    proxyStream.emit('error', err);
  }
});

That what users of client.upload can subscribe to the error and handle it properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions