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

Decoding empty body resulted in syntax error #2668

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

jms-pantheon
Copy link
Collaborator

Previously when in verbose mode, Terminus would report [debug] Syntax error at the end of a request.

When there is no body in the response, there's no need to attempt to decode it. We set it to null here.

@jms-pantheon jms-pantheon requested a review from a team as a code owner January 31, 2025 00:10
@greg-1-anderson
Copy link
Member

Build error says: "The maximum number of Multidev environment for this service level has been reached." 😿

JSON_THROW_ON_ERROR
);
} catch (\JsonException $jsonException) {
$this->logger->debug($jsonException->getMessage());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should prepend a string in front of jsonException->getMessage() to make this line easier to find should it happen again in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% agree, and $body should not overwrite $body on line 434. we should preserve the body before attempting json decode, and print what was in it if the json decode fails.


// Don't attempt to decode JSON if the response is expected to have no body.
if (
!in_array($statusCode, [204, 304], true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful to be more explicit (i.e., explain in a comment) the significance of these particular status codes, and why this check is important to do in addition to the content-length / empty body checks.

Comment on lines +442 to +445
$body = null;
}
} else {
$body = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why force null?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants