Skip to content

Comments

Fix: deploy command crashes on API response string access#15

Draft
fthues wants to merge 2 commits intoploi:mainfrom
fthues:fix/deploy-response-string-access
Draft

Fix: deploy command crashes on API response string access#15
fthues wants to merge 2 commits intoploi:mainfrom
fthues:fix/deploy-response-string-access

Conversation

@fthues
Copy link

@fthues fthues commented Feb 15, 2026

Problem

ploi deploy crashes with two separate type errors after the deploy API call succeeds.

Bug 1: String offset access on deploy response (line 102)

Cannot access offset of type string on string

Root cause: Line 102 does:

$this->info(Arr::first($deploying['data'])['message']);

The deploy API returns {"message": "Deploy queued successfully"} (no data wrapper). After PloiAPI::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)

Return value must be of type ?int, string returned

Root cause: getLatestDeploymentId() declares ?int return 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']:

$firstValue = Arr::first($deploying['data']);
$this->info(is_array($firstValue) ? $firstValue['message'] : $firstValue);

This handles both response shapes:

  • data as array of objects (original expectation): extracts ['message'] from the first element
  • data as flat associative array (actual API response): uses the string value directly

Fix 2: Deployment ID type cast

Cast the API response value to int:

return isset($deployment['id']) ? (int) $deployment['id'] : null;

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.
@fthues fthues marked this pull request as draft February 15, 2026 10:35
@Naoray
Copy link

Naoray commented Feb 16, 2026

hitting the same error

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.

2 participants