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: node.js debugger adds stderr (but exit code is 0) -> shouldn't throw #2719

Merged
merged 2 commits into from Aug 22, 2022

Conversation

FuPeiJiang
Copy link
Contributor

Debugger attached.
Waiting for the debugger to disconnect...

Checklist
  • npm install && npm test passes
  • tests are included
  • documentation is changed or added
  • commit message follows commit guidelines
Description of change

Comment on lines 982 to 986
if p.wait() != 0:
sys.stderr.write(p_stderr)
# Simulate check_call behavior, since check_call only exists
# in python 2.5 and later.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if p.wait() != 0:
sys.stderr.write(p_stderr)
# Simulate check_call behavior, since check_call only exists
# in python 2.5 and later.
if p_stderr:
sys.stderr.write(p_stderr)
if p.wait() != 0:

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a simple way that this code can detect the presence of the debugger?

Copy link
Contributor

@cclauss cclauss Aug 19, 2022

Choose a reason for hiding this comment

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

If we are going to make changes here, the recommended path is to upgrade to subprocess.run() to remove a lot of clutter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

keep comments ? (I think it's for the raise below) (keep/delete) ?

                        # Simulate check_call behavior, since check_call only exists
                        # in python 2.5 and later.
                        raise GypError(
                            "Call to '%s' returned exit status %d while in %s."
                            % (contents, p.returncode, build_file)
                        )

this is better behavior, no loss of stderr output (possible useful debug log)

Copy link
Contributor

@cclauss cclauss Aug 19, 2022

Choose a reason for hiding this comment

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

We do not need the comment about Py25... subprocess.check_cal() is fully available to us on all supported versions of Python and the even simpler subprocess.run() is too.

Will all users have the debugger present? If not, what is the effect of the proposed changes on those users?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what is the effect of the proposed changes on those users?

<!(node -p \"require('node-addon-api').gyp\")

oof, the scope is Any command..


Is there a simple way that this code can detect the presence of the debugger?

there may be another way: silence the:

Debugger attached.
Waiting for the debugger to disconnect...

https://github.com/nodejs/node/blob/fddc701d3c0eb4520f2af570876cc987ae6b4ba2/src/inspector_agent.cc#L802-L805
It seems that it only prints if no parent
python spawning seems like a parent ? I'll have to check more

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stderr doesn’t mean error,
Status code > 0 means error

Yes, programs can output to standard error and still return a zero exit status. You will find many POSIX utilities specifications which state that "The standard error shall be used only for diagnostic messages."

https://unix.stackexchange.com/a/594670

this is the correct handling

If any program wants to indicate error, just set status code

Comment on lines 985 to 986
# Simulate check_call behavior, since check_call only exists
# in python 2.5 and later.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Simulate check_call behavior, since check_call only exists
# in python 2.5 and later.

Remove.

@FuPeiJiang
Copy link
Contributor Author

the tests aren't even re-ran after force-push, this broke 2 tests

@FuPeiJiang
Copy link
Contributor Author

it's checking if the last line of stderr === 'gyp info ok'
but now it's === 'Waiting for the debugger to disconnect...'

@FuPeiJiang
Copy link
Contributor Author

FuPeiJiang commented Aug 19, 2022

nevermind, no breaking changes,
these 2 tests were always meant to fail in JavaScript Debug Terminal
and they were always meant to succeed in Not JavaScript Debug Terminal
(has nothing to do with input.py)

@FuPeiJiang
Copy link
Contributor Author

I feel that checking the last line of something isn't a foolproof way of checking for success, maybe exit code ? I'll have to check the intention

)
replacement = p_stdout.rstrip()
replacement = result.stdout.decode("utf-8").rstrip()
Copy link
Contributor

Choose a reason for hiding this comment

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

Add text = True to the run() call and then...

Suggested change
replacement = result.stdout.decode("utf-8").rstrip()
replacement = result.stdout.rstrip()

cwd=build_file_dir,
check=False
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
check=False
check=False,
text=True

@FuPeiJiang
Copy link
Contributor Author

fails python 3.6 tests
revert change text=True

Changed in version 3.7: Added the text parameter, as a more understandable alias of universal_newlines. Added the capture_output parameter.

https://docs.python.org/3/library/subprocess.html#:~:text=Changed%20in%20version%203.7%3A%20Added%20the%20text%20parameter%2C%20as%20a%20more%20understandable%20alias%20of%20universal_newlines.%20Added%20the%20capture_output%20parameter.

Copy link
Contributor

@cclauss cclauss left a comment

Choose a reason for hiding this comment

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

LGTM (Once all tests are passing ;-) )

@cclauss
Copy link
Contributor

cclauss commented Aug 22, 2022

Yes. Py36 is end-of-life https://devguide.python.org/versions so we should drop support for it but let's move this forward as is.

@cclauss cclauss merged commit c379a74 into nodejs:main Aug 22, 2022
@rvagg
Copy link
Member

rvagg commented Oct 4, 2022

this shouldn't have been merged here but over in gyp-next: https://github.com/nodejs/gyp-next/blob/main/pylib/gyp/input.py

I believe it's going to get overwritten with a upgrade. @FuPeiJiang would you mind doing an equivalent PR over there please?

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.

None yet

3 participants