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

print stacktraces during import errors #10906

Conversation

cosmicexplorer
Copy link
Contributor

@cosmicexplorer cosmicexplorer commented Oct 5, 2020

[ci skip-rust]

Problem

Pants only prints what failed to import upon an ImportError, not where.

@coveralls
Copy link

coveralls commented Oct 5, 2020

Coverage Status

Coverage remained the same at 0.0% when pulling 3431bbe on cosmicexplorer:log-stacktrace-on-import-error into 923f461 on pantsbuild:master.

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@cosmicexplorer cosmicexplorer force-pushed the log-stacktrace-on-import-error branch from 5f3e4cc to 8902834 Compare October 5, 2020 07:09
if cls._logging_initialized:
logger.exception(exc)
else:
exception_log_entry = cls._format_unhandled_exception_log(
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if we get rid of the logic for checking and setting cls._logging_initialized and just always use the cls._format_unhandled_exception_log form? If I understand https://docs.python.org/3.6/library/logging.html#logging.Logger.exception correcty, logger.exception and logger.error should both be writing fairly similar text to the Rust logging faculty, once it's been initialized. If we could get away with just modifying this one line to print the additional context we need for import-time errors, without adding any additional logic to think about in this class, I think that would be ideal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That works, but why doesn't it print the stacktrace twice when we send the rust logger the stacktrace? What is it doing such that sending it the exception vs a completely different string with the exception + stacktrace produces the same output?

Copy link
Contributor

Choose a reason for hiding this comment

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

That works, but why doesn't it print the stacktrace twice when we send the rust logger the stacktrace? What is it doing such that sending it the exception vs a completely different string with the exception + stacktrace produces the same output?

I'm not sure. Does anything change if you call logger.error with the string generated by format_unhandled_exception_log rather than logger.exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No! Which is so weird! I would like to understand this part further, because it's not immediately clear to me, but I wasn't able to easily figure it out by scanning the rust logger implementation, and the right behavior still seems to occur on --no-print-exception-stacktrace.

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@gshuflin
Copy link
Contributor

gshuflin commented Oct 6, 2020

[ci skip-rust]

Problem

Pants only prints what failed to import upon an ImportError, not where.

Solution

* Add `ExceptionSink._logging_initialized` class-level field, toggled on with `ExceptionSink.set_logging_initialized()`.

* Set `ExceptionSink.set_logging_initialized()` after setting up the rust logger.

Commit message needs to be updated

@cosmicexplorer cosmicexplorer merged commit 6eea7c4 into pantsbuild:master Oct 7, 2020
@Eric-Arellano Eric-Arellano mentioned this pull request Oct 11, 2020
Eric-Arellano added a commit that referenced this pull request Oct 12, 2020
Internal only changes left off from the changelog:

* Use cpython types in Rust functions that manipulate python objects (#10942)
  `PR #10942 <https://github.com/pantsbuild/pants/pull/10942>`_

* update libz-sys version to fix macOS compile error (#10941)
  `PR #10941 <https://github.com/pantsbuild/pants/pull/10941>`_

* Upgrade to Rust stable 1.47.0. (#10933)
  `PR #10933 <https://github.com/pantsbuild/pants/pull/10933>`_

* Finish CreateDigest Directory cleanup. (#10935)
  `PR #10935 <https://github.com/pantsbuild/pants/pull/10935>`_

* Hotfix broken import from merge conflict (#10934)
  `PR #10934 <https://github.com/pantsbuild/pants/pull/10934>`_

* Revert "Port nailgun client to rust (#10865)" (#10929)
  `PR #10929 <https://github.com/pantsbuild/pants/pull/10929>`_

* An ExternalTool for downloading the grpc_python_plugin. (#10927)
  `PR #10927 <https://github.com/pantsbuild/pants/pull/10927>`_

* Port nailgun client to rust (#10865)
  `PR #10865 <https://github.com/pantsbuild/pants/pull/10865>`_

* print stacktraces during import errors (#10906)
  `PR #10906 <https://github.com/pantsbuild/pants/pull/10906>`_

* fs.Digest is declared in Rust (#10905)
  `PR #10905 <https://github.com/pantsbuild/pants/pull/10905>`_

* add requests_ca_bundle to settable_env_vars (#10909)
  `PR #10909 <https://github.com/pantsbuild/pants/pull/10909>`_

[ci skip-rust]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants