Skip to content

pubsub: unhelpful error message when trying to publish a string. #500

Description

@tmatsuo

When I do the following:

topic.publish('New message!', function(err) }
}

I get:

buffer.js:188
        throw new TypeError('First argument needs to be a number, ' +
              ^
TypeError: First argument needs to be a number, array or string.
    at new Buffer (buffer.js:188:15)
    at Topic.formatMessage_ (/usr/local/google/home/tmatsuo/node_modules/gcloud/lib/pubsub/topic.js:80:20)
    at Array.map (native)
    at Topic.publish (/usr/local/google/home/tmatsuo/node_modules/gcloud/lib/pubsub/topic.js:183:24)
    at null._onTimeout (/usr/local/google/home/tmatsuo/tmp/mayran/mysubscribe.js:44:27)
    at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)

Under the cover, the code is trying to make message.data (which is undefined) a buffer:

Topic.formatMessage_ = function(message) {
  if (!util.is(message.data, 'buffer')) {
    message.data = new Buffer(JSON.stringify(message.data));
  }

  message.data = message.data.toString('base64');

  return message;
};

Maybe type check first and give helpful error messages?

Activity

  1. added a commit that references this issue on Apr 14, 2015
    b6ba3e9
  2. stephenplusplus commented on Apr 14, 2015

    @stephenplusplus
    Contributor

    Good idea. PR sent!

  3. added a commit that references this issue on Apr 15, 2015
    64b6140
  4. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    api: pubsubIssues related to the Pub/Sub API.
    on May 14, 2015
  5. 12 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

🚨This issue needs some love.api: pubsubIssues related to the Pub/Sub API.triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions