Skip to content

The emitterFor() function drops additional defaults when an option is provided #391

@lance

Description

@lance

Describe the Bug
When calling emitterFor(), if you provide an option, as in the README example, it will fail. Example:

const emit = emitterFor(sendWithAxios, { binding: HTTP });

Produces the failure message:

(node:2623360) UnhandledPromiseRejectionWarning: TypeError: Unexpected transport mode: undefined
    at emit (/home/lanceball/src/github.com/lance/ce/node_modules/cloudevents/dist/transport/emitter.js:41:23)
    at Function.<anonymous> (/home/lanceball/src/github.com/lance/ce/node_modules/cloudevents/dist/transport/emitter.js:96:87)
    at Generator.next (<anonymous>)
    at /home/lanceball/src/github.com/lance/ce/node_modules/cloudevents/dist/transport/emitter.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/lanceball/src/github.com/lance/ce/node_modules/cloudevents/dist/transport/emitter.js:4:12)
    at /home/lanceball/src/github.com/lance/ce/node_modules/cloudevents/dist/transport/emitter.js:96:33
    at Array.map (<anonymous>)
    at Function.<anonymous> (/home/lanceball/src/github.com/lance/ce/node_modules/cloudevents/dist/transport/emitter.js:96:22)
    at Generator.next (<anonymous>)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2623360) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:2623360) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This is because the defaults are dropped when a parameter is provided here:

const { binding, mode } = options;

Steps to Reproduce

  1. Copy one of the emitterFor() examples into an index.js file.
  2. Create a local process that can receive CloudEvents and change the URL in the example code to point to this
  3. Install axios and cloudevents modules locally
  4. Run node index.js

Expected Behavior
The event viewer process should receive the event and respond with a success code. Instead, we don't get that far because of failure. In fact, you don't even really need step 2 above, since the failure occurs before a request is made.

Metadata

Metadata

Assignees

Labels

module/libRelated to the main source codemodule/transport/httpIssues related to the HTTP transport protocol implementationtype/bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions