Skip to content

Remove return value from generateResponse() prepare method #4299

Closed

Description

@kanongil

Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): probably not

Context

  • node version: any
  • module version: 20.2.1
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...):
  • any other relevant information:

What are you trying to achieve or the steps to reproduce?

The request.generateResponse() takes a prepare(response) option that must return a response (existing or new).

hapi/lib/toolkit.js

Lines 104 to 106 in 404d253

if (!response.isBoom && response._state === 'init') {
response = await response._prepare();
}

return this._processors.prepare(this);

Returning anything other than the existing response is however fundamentally broken since:

  1. Returned value is not validated for correctness.
  2. It causes the close() option to never be called.
  3. It is not feasible to actually create, since there is no Toolkit to create it from. Only request.generateResponse() is available, and if used can break since the prepare() option is never called for it.

Given the above, I expect the feature has never been used and I suggest it is simply removed. Especially since there is no test code that covers this, or any pertinent use cases. Any return value should just be ignored. The feature is likely a vestige from when returned errors would be handled.

FYI the generateResponse() prepare option is currently only used in inert and vision.

Activity

  1. kanongil commented on Oct 9, 2021

    @kanongil
    ContributorAuthor

    While this is definitely a breaking change (the docs will have to change), I feel that it would be fair to remove such a broken feature on the current release.

  2. devinivy commented on Oct 9, 2021

    @devinivy
    Member

    I fully agree that this is broken, but I do have some concerns about removing it in v20. If someone is using the functionality, updating this and changing their responses could have worse effects for them than the bugs mentioned above. And if nobody is using it, then this issue doesn't affect anyone. I would be all for updating the docs now to discourage the behavior, then updating the code in v21. I also would be open to handling the case of no return value in v20 by assuming the response hasn't been changed.

  3. kanongil commented on Oct 10, 2021

    @kanongil
    ContributorAuthor

    I guess you are right. My main concern is that someone might add new code that tries to depend on this. But that is probably quite unlikely.

  4. added a commit that references this issue on Oct 12, 2021
  5. devinivy commented on Nov 7, 2022

    @devinivy
    Member

    Resolved with v21 #4386

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changesChange that can breaking existing codebugBug or defect

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions