Skip to content

fix(resources:set): stop interactive prompts crashing on numeric defaults#105

Open
pjcdawkins wants to merge 1 commit into
mainfrom
fix/resources-set-instance-count-typeerror
Open

fix(resources:set): stop interactive prompts crashing on numeric defaults#105
pjcdawkins wants to merge 1 commit into
mainfrom
fix/resources-set-instance-count-typeerror

Conversation

@pjcdawkins

@pjcdawkins pjcdawkins commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Problem

upsun resources:set, run interactively, crashes with a fatal TypeError the moment the user presses Enter at the "Enter the number of instances" prompt:

TypeError: ResourcesSetCommand::validateInstanceCount(): Argument #1 ($value)
must be of type string, int given

The interactive prompts pass the current value as the default straight to the validator when the user accepts it. instance_count and disk are ints, but the validators type $value as string, and the command file declares strict_types=1. autoscaling:set has the same prompts (instances min/max) and the same crash.

Why it got past PHPStan

The validators are invoked through a closure (fn($v) => $this->validateInstanceCount($v, ...)) whose $v is an implicit mixed. At level 8 PHPStan permits an implicit mixed to flow into a string parameter, and the int default only reaches the validator at runtime via Symfony's QuestionHelper.

Fix

Symfony runs the default through the validator when the user accepts it. Console input is always text, so QuestionHelper::askInput() now coerces the default to a string when a validator is set. This fixes the whole class of prompt at the source — every validator is guaranteed a string whether the user types a value or accepts the default — and lets the validators stay honestly string-typed. No call sites change.

Test

Adds integration-tests/resources_set_interactive_test.go, which drives resources:set interactively and accepts the defaults. It reproduces the TypeError against the unfixed build and passes with the fix.

Copilot AI review requested due to automatic review settings June 13, 2026 12:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a fatal TypeError in interactive flows where Symfony’s QuestionHelper can pass an int default directly into validators under strict_types=1. This aligns the legacy CLI’s interactive prompting behavior with the validators’ intended “cast-to-int then validate” logic.

Changes:

  • Widened validateInstanceCount() / validateDiskSize() parameter types to int|string in ResourcesSetCommand.
  • Widened AutoscalingSettingsSetCommand::validateInstanceCount() parameter type to int|string for the same interactive-default behavior.
  • Added an integration test that drives resources:set interactively and accepts defaults to prevent regressions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
legacy/src/Command/Resources/ResourcesSetCommand.php Accepts int defaults in interactive validators to avoid TypeError under strict types.
legacy/src/Command/Autoscaling/AutoscalingSettingsSetCommand.php Aligns autoscaling instance-count validator with interactive defaults (int) behavior.
integration-tests/resources_set_interactive_test.go Adds regression coverage for accepting interactive defaults without crashing.
Comments suppressed due to low confidence (1)

legacy/src/Command/Resources/ResourcesSetCommand.php:560

  • validateDiskSize() documents support for the special values 'default'/'min'/'minimum' (see the --disk option help), but the current numeric validation runs before those keyword branches. On PHP >= 8 this means non-numeric strings like "default" will fail $size != $value and throw before reaching the keyword handling.

Consider skipping the numeric validation when the user entered one of the supported keywords (or moving the keyword handling above the numeric validation).

    protected function validateDiskSize(int|string $value, string $serviceName, WebApp|Worker|Service $service): int
    {
        if (!$this->resourcesUtil->supportsDisk($service)) {
            throw new InvalidArgumentException(sprintf(
                'The %s <error>%s</error> does not support a persistent disk.',

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pjcdawkins pjcdawkins force-pushed the fix/resources-set-instance-count-typeerror branch from e5f8560 to 7129f7f Compare June 14, 2026 09:38
@pjcdawkins pjcdawkins changed the title fix(resources:set): accept int default in instance count and disk validators fix(resources:set): stop interactive prompts crashing on numeric defaults Jun 14, 2026
@pjcdawkins pjcdawkins force-pushed the fix/resources-set-instance-count-typeerror branch from 7129f7f to be42d97 Compare June 14, 2026 09:51
…ults

resources:set and autoscaling:set crashed with a fatal TypeError when the
user accepted an interactive default (e.g. "Enter the number of instances",
default 1). QuestionHelper::askInput() passed the default - an int - straight
to the validator, whose $value is typed string under the command's strict_types.

Symfony runs the default through the validator when the user accepts it, so
coerce the default to a string inside askInput() when a validator is set.
Validators validate typed text, so this matches what typed input provides; it
fixes every such prompt at the source and lets validators stay string-typed.

PHPStan (level 8) did not catch the original mismatch: the validators are
called via a closure with an implicit mixed parameter, which level 8 allows to
pass to a string parameter, and the int default only arrives at runtime.

Add an interactive integration test covering the resources:set form: accepting
the defaults changes nothing, and entering new values submits them in the
deployment update.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pjcdawkins pjcdawkins force-pushed the fix/resources-set-instance-count-typeerror branch from be42d97 to bcbea2e Compare June 14, 2026 10:14
@pjcdawkins pjcdawkins requested a review from Copilot June 14, 2026 10:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

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