Skip to content

ChildProcess: account for a system error when launching a process #66

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

Merged
merged 2 commits into from
Mar 22, 2025

Conversation

Hi-Angel
Copy link
Contributor

@Hi-Angel Hi-Angel commented Mar 21, 2025

Description of the change

When a non-existing command is attempted to run, both status and signal will be null, which leads to ChildProcess module crashing. Obviously, this is incorrect behavior.

The problem is more general than that though: any system error that would result in failing to run a process would result in the module crash.

Fix that by checking for such case.

Fixes: #65


Checklist:

  • Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

@Hi-Angel Hi-Angel force-pushed the account-for-sys-errors branch 3 times, most recently from f68dff5 to f0f0f73 Compare March 21, 2025 10:22
Copy link
Member

@garyb garyb left a comment

Choose a reason for hiding this comment

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

Nice! 👍

@Hi-Angel
Copy link
Contributor Author

Thanks!

CI fails seems unrelated, perhaps aff module needs to be declared in configs… I didn't manage to build the project locally too, been testing my changes by copying into a separate project.

@Hi-Angel Hi-Angel force-pushed the account-for-sys-errors branch from f0f0f73 to d8e18be Compare March 21, 2025 21:40
@Hi-Angel
Copy link
Contributor Author

Managed to build it locally, and yes, in bower.json there was aff dep missing.

I fixed it in a separate commit, please tell if you want it to be sent in a separate PR.

@Hi-Angel Hi-Angel force-pushed the account-for-sys-errors branch from d8e18be to 54c8016 Compare March 22, 2025 12:59
@Hi-Angel Hi-Angel force-pushed the account-for-sys-errors branch from 54c8016 to a95fb6e Compare March 22, 2025 13:01
@Hi-Angel
Copy link
Contributor Author

I am not exactly sure what purs-tidy complains about…

Screenshot_20250322_161226

I tried moving if to the next line and running purs-tidy locally, but it still complains.

I mean, the only other possible change that I see is making entire if-then-else branch a single line…

@garyb
Copy link
Member

garyb commented Mar 22, 2025

Ah yeah, purs-tidy won't like that if/then formatting - you can just run it to format the code rather than using check, but it probably won't look great with what it does either. I'll make a suggestion that it should be happy with.

Comment on lines 240 to 242
_, _ -> if isJust $ toMaybe r.error
then BySysError
else unsafeCrashWith $ "Impossible: `spawnSync` child process neither exited nor was killed."
Copy link
Member

@garyb garyb Mar 22, 2025

Choose a reason for hiding this comment

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

Suggested change
_, _ -> if isJust $ toMaybe r.error
then BySysError
else unsafeCrashWith $ "Impossible: `spawnSync` child process neither exited nor was killed."
_, _ ->
if isJust (toMaybe r.error) then
BySysError
else
unsafeCrashWith "Impossible: `spawnSync` child process neither exited nor was killed."

Copy link
Member

Choose a reason for hiding this comment

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

Or option 2:

Suggested change
_, _ -> if isJust $ toMaybe r.error
then BySysError
else unsafeCrashWith $ "Impossible: `spawnSync` child process neither exited nor was killed."
_, _
| isJust (toMaybe r.error) -> BySysError
| otherwise -> unsafeCrashWith "Impossible: `spawnSync` child process neither exited nor was killed."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I like this one! Let me try this

Copy link
Member

Choose a reason for hiding this comment

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

Ah sorry, didn't see this message until now 😄 I think either way is fine though stylistically, and they should compile to pretty much the same JS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's okay and thank you!

When a non-existing command is attempted to run, both status and
signal will be null, which leads to ChildProcess module crashing.
Obviously, this is incorrect behavior.

The problem is more general than that though: any system error that
would result in failing to run a process would result in the module
crash.

Fix that by checking for such case.

Fixes: purescript-node#65
@Hi-Angel Hi-Angel force-pushed the account-for-sys-errors branch from a95fb6e to 60eec01 Compare March 22, 2025 13:21
@Hi-Angel
Copy link
Contributor Author

Thank you, done!

@garyb
Copy link
Member

garyb commented Mar 22, 2025

Thanks!

@garyb garyb merged commit a836ddd into purescript-node:master Mar 22, 2025
1 check passed
@garyb
Copy link
Member

garyb commented Mar 22, 2025

Now released as v12.0.0 - even though this was a bug fix, the introduction of BySysError makes it a breaking change, as if there's existing code out there pattern matching on Exit it would no longer be an exhaustive match. 🙂

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.

"Impossible:" errors whenever a command to be run doesn't exist
2 participants