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

Fix NaN issue in Execa by extracting .stdout #629

Merged
merged 12 commits into from
Feb 27, 2025
Merged

Conversation

ProchaLu
Copy link
Member

@ProchaLu ProchaLu commented Feb 27, 2025

Closes #588

The Preflight Docker container failed when trying to set the uid for the PostgreSQL setup script. The issue was that Execa returns an object, and Number() was called on the object instead of just the command output, resulting in NaN. This caused Execa to throw this error:

'The "options.uid" property must be int32. Received type number (NaN)'

It wasn’t clear why the value was NaN. We assumed that execa returned a string, but it returns an object containing the command output under .stdout. It failed because Number() was called on the entire object instead of extracting .stdout first.

const postgresUid = Number(await execa`id -u postgres`); // Fails: Execa result object → NaN

To fix this error, we need to extract .stdout before converting to a number.

const postgresUid = Number((await $`id -u postgres`).stdout); // Works: Extracts string output

ESLint didn’t catch this issue because Number({}) is currently not flagged as an error. A proposal has been made to TypeScript ESLint to introduce a rule preventing passing objects to Number().

Copy link

codesandbox-ci bot commented Feb 27, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

const postgresUid = Number(await execa`id -u postgres`);
const postgresUid = Number((await $`id -u postgres`).stdout);
Copy link
Member

Choose a reason for hiding this comment

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

looks like the execa identifier isn't just the one imported directly from the 'execa' package, but it's this:

const projectPath = 'project-to-check';
const execa = bindExeca({ cwd: projectPath });

so probably we need to stick with using the execa identifier, or do a bigger change to switch everything to $, with this binding

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to execa. cfc6c4e

@ProchaLu
Copy link
Member Author

ProchaLu commented Feb 27, 2025

While debugging this issue, we discovered that Execa $ shorthand behaves differently depending on how it's used. Inside an Execa command, interpolation automatically extracts .stdout:

await $`dep deploy --branch=${branch}`; // Works: `branch.stdout` is extracted correctly

When assigning the result to a variable, Execa returns an object, not a string, which led to the NaN issue in our case

const branch = await $`git branch --show-current`;
console.log(branch); // Logs: [object Object]

Copy link
Member

@karlhorky karlhorky left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@karlhorky karlhorky merged commit 916d0ec into main Feb 27, 2025
6 checks passed
@karlhorky karlhorky deleted the fix-preflight-postgresuid branch February 27, 2025 18:52
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.

Preflight Docker container with PostgreSQL database: opts.uid is NaN
2 participants