Fix: deploy command crashes on API response string access#15
Draft
Fix: deploy command crashes on API response string access#15
Conversation
The deploy API returns `{"message": "Deploy queued successfully"}` without
a `data` wrapper. After `makeRequest()` processes this, `$deploying['data']`
is `['message' => 'Deploy queued successfully']`. `Arr::first()` returns
the string value, not an array, so indexing with `['message']` crashes:
`Cannot access offset of type string on string`.
Check whether the first value is an array before accessing its `message`
key. This handles both response shapes gracefully.
`getLatestDeploymentId()` declares `?int` return type but the API returns the deployment ID as a string. Cast to `(int)` to satisfy the type declaration.
|
hitting the same error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ploi deploycrashes with two separate type errors after the deploy API call succeeds.Bug 1: String offset access on deploy response (line 102)
Root cause: Line 102 does:
The deploy API returns
{"message": "Deploy queued successfully"}(nodatawrapper). AfterPloiAPI::makeRequest()processes this,$deploying['data']is the associative array['message' => 'Deploy queued successfully'].Arr::first()on that array returns the string"Deploy queued successfully", then['message']fails because you can't index into a string.Bug 2: String returned for int return type (line 190)
Root cause:
getLatestDeploymentId()declares?intreturn type, but the API returns the deployment ID as a string. The$deployment['id']value is a string, which violates the declared return type.Fix
Fix 1: Deploy response handling
Check whether
Arr::first()returns an array or a string before trying to access['message']:This handles both response shapes:
dataas array of objects (original expectation): extracts['message']from the first elementdataas flat associative array (actual API response): uses the string value directlyFix 2: Deployment ID type cast
Cast the API response value to int: