Skip to content

Enrich remote exceptions with worker info - #7847

Closed
j-bennet wants to merge 50 commits into
dask:mainfrom
j-bennet:j-bennet/4880-cleanup-remote-tracebacks
Closed

j-bennet wants to merge 50 commits into
dask:mainfrom
j-bennet:j-bennet/4880-cleanup-remote-tracebacks

Conversation

@j-bennet

@j-bennet j-bennet commented May 19, 2023 •

Copy link
Copy Markdown
Contributor

Part of #4880.

Depends on dask/dask#10354.

Adds information about worker and task to exception str(). When the exception is printed by excepthook, it looks like this:

ValueError: Bad block id (2,)
in task: ('throws_map_blocks-ea77cec762bc72be73248e7d1ca88e18', 2)
on worker: {'tcp://127.0.0.1:61285'}

Example:

import distributed

class BadNumbers(Exception):
    def __str__(self):
        return "I didn't like these numbers: " + " ".join(f"{x:.1f}" for x in self.args)

def f():
    raise BadNumbers(1, 2.5, 3)

client = distributed.Client()
client.submit(f).result()

2023-06-23 17:30:12,863 - distributed.worker - WARNING - Compute Failed
Key:       f-b99bfd3c9f23830749c47a75563c3283
Function:  f
args:      ()
kwargs:    {}
Exception: 'BadNumbers(1, 2.5, 3)'

---------------------------------------------------------------------------
BadNumbers                                Traceback (most recent call last)
Cell In[4], line 2
      1 client = distributed.Client()
----> 2 client.submit(f).result()

Cell In[3], line 2, in f()
      1 def f():
----> 2     raise BadNumbers(1, 2.5, 3)

BadNumbers: I didn't like these numbers: 1.0 2.5 3.0
in task: f-b99bfd3c9f23830749c47a75563c3283
on worker: {'tcp://127.0.0.1:56485'}
  • Tests added / passed
  • Passes pre-commit run --all-files

@j-bennet
j-bennet requested a review from fjetter as a code owner May 19, 2023 23:43
@GPUtester

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

Admins can comment ok to test to allow this one PR to run or add to allowlist to allow all future PRs from the same author to run.

@j-bennet
j-bennet marked this pull request as draft May 19, 2023 23:43
@github-actions

github-actions Bot commented May 20, 2023 •

Copy link
Copy Markdown
Contributor

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

       20 files  ±0         20 suites  ±0   10h 55m 52s ⏱️ - 27m 41s
  3 698 tests ±0    3 585 ✔️  - 3     106 💤 ±0  7 ❌ +3 
35 766 runs  ±0  34 011 ✔️  - 2  1 748 💤 ±0  7 ❌ +2 

For more details on these failures, see this check.

Results for commit b8478c1. ± Comparison against base commit e0dbb35.

♻️ This comment has been updated with latest results.

@j-bennet j-bennet changed the title [WIP] Cleanup remote tracebacks Cleanup remote tracebacks May 22, 2023
@j-bennet

Copy link
Copy Markdown
Contributor Author

@fjetter I'd appreciate if you could take a look at this. In #4880, it is also requested that we add worker name and task info to the exception output. In distributed.Client, I'm not sure where to get this information.

@fjetter

fjetter commented May 23, 2023

Copy link
Copy Markdown
Member

it is also requested that we add worker name and task info to the exception output. In distributed.Client, I'm not sure where to get this information.

You shouldn't consider what's in this ticket as a request but rather as a suggestion. If we don't have this information easily available, this should not drive implementation effort

@j-bennet
j-bennet marked this pull request as ready for review May 24, 2023 22:02
@j-bennet

j-bennet commented May 24, 2023 •

Copy link
Copy Markdown
Contributor Author

@fjetter

You shouldn't consider what's in this ticket as a request but rather as a suggestion. If we don't have this information easily available, this should not drive implementation effort

Your response in Slack was helpful with this part. I'd rather not override the built-in formatting method to print a custom header on top of an exception, and I don't want to wrap it with a custom Exception, or attach a made-up context, so the easiest thing to do was tucking it into exception args, even though this is not quite as pretty.

See what you think.

@j-bennet
j-bennet force-pushed the j-bennet/4880-cleanup-remote-tracebacks branch from bdb2e3d to 10ec8e3 Compare May 24, 2023 22:56
@j-bennet

Copy link
Copy Markdown
Contributor Author

@crusaderky This PR was reworked, and now the only thing it does is pushing worker info into remote exception. Actual traceback cleanup is done in dask/dask#10354. Please take a look. It seems to me that test failures are not related.

@j-bennet
j-bennet marked this pull request as ready for review June 16, 2023 01:34
Comment thread distributed/client.py Resolved
@j-bennet
j-bennet force-pushed the j-bennet/4880-cleanup-remote-tracebacks branch from 44d2f1f to 84464b9 Compare June 20, 2023 17:49

@crusaderky crusaderky left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add unit tests

Comment thread distributed/client.py Resolved
Comment thread distributed/client.py Resolved
Comment thread distributed/client.py Outdated
exception.args = (worker_message,)
else:
arg0 = f"{exception.args[0]}\n{worker_message}"
exception.args = (arg0,) + exception.args[1:]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What kind of exception is this? is this a specific exception type raised by distributed?
args can contain very different things depending on the exception subclass and this change will break many custom exceptions.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This comment has not been addressed.
In fact, I can very easily make it break:

class BadNumbers(Exception):
    def __str__(self):
        return "I didn't like these numbers: " + " ".join(f"{x:.1f}" for x in self.args)

def f():
    raise BadNumbers(1, 2.5, 3)
    
f()

---------------------------------------------------------------------------
BadNumbers                                Traceback (most recent call last)
Cell In[10], line 8
      5 def f():
      6     raise BadNumbers(1, 2.5, 3)
----> 8 f()

Cell In[10], line 6, in f()
      5 def f():
----> 6     raise BadNumbers(1, 2.5, 3)

BadNumbers: I didn't like these numbers: 1.0 2.5 3.0

import distributed
client = distributed.Client()
client.submit(f).result()

Custom TB Handler failed, unregistering
---------------------------------------------------------------------------
BadNumbers                                Traceback (most recent call last)
    [... skipping hidden 1 frame]

Cell In[12], line 1
----> 1 c.submit(f).result()

Cell In[10], line 6, in f()
      5 def f():
----> 6     raise BadNumbers(1, 2.5, 3)

<class 'str'>: (<class 'ValueError'>, ValueError("Unknown format code 'f' for object of type 'str'"))
[...]
TypeError: structured_traceback() missing 1 required positional argument: 'evalue'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah. I addressed this comment here:

#7847 (comment)

But I changed the implementation since, so it's not relevant anymore.

Comment thread distributed/client.py Resolved
j-bennet and others added 3 commits June 22, 2023 00:29
Co-authored-by: crusaderky <[email protected]>
Co-authored-by: crusaderky <[email protected]>
@j-bennet
j-bennet requested a review from crusaderky June 22, 2023 00:48
@crusaderky

Copy link
Copy Markdown
Collaborator

As it is right now, I do not think this PR is a good idea, at all.
Maybe instead of tampering with exception args we could just call logging.error() when the client re-raises?

@j-bennet

Copy link
Copy Markdown
Contributor Author

As it is right now, I do not think this PR is a good idea, at all. Maybe instead of tampering with exception args we could just call logging.error() when the client re-raises?

That's a nice breaking example. I think we have a couple of options here, they each have their drawback. One, like you said, could be logging.error(), but that still means any unhandled exception would not have worker info. Another option would be re-raising a custom exception with worker info in it (what I wanted to avoid), but that adds another traceback level. Which do you think would be better?

@crusaderky

Copy link
Copy Markdown
Collaborator

Re-raising a wrapper exception would make the traceback less readable and break backwards compatibility.

but that still means any unhandled exception would not have worker info.

I don't follow. You'd just call logger.error from Future.result() or whatever re-raises the exception.

@j-bennet

Copy link
Copy Markdown
Contributor Author

@crusaderky

Re-raising a wrapper exception would make the traceback less readable and break backwards compatibility.

I agree. I tried another way, and it might actually solve that problem. It solves the problem with BadNumbers error. See what you think.

@j-bennet j-bennet changed the title Cleanup remote tracebacks (enrich with worker info) Enrich remote tracebacks with worker info Jun 23, 2023
@j-bennet j-bennet changed the title Enrich remote tracebacks with worker info Enrich remote exceptions with worker info Jun 23, 2023
@j-bennet
j-bennet force-pushed the j-bennet/4880-cleanup-remote-tracebacks branch from 08a82c3 to e79bda2 Compare June 23, 2023 21:57
@j-bennet j-bennet mentioned this pull request Jun 23, 2023
2 tasks done
@j-bennet

j-bennet commented Jun 23, 2023 •

Copy link
Copy Markdown
Contributor Author

@crusaderky

I don't follow. You'd just call logger.error from Future.result() or whatever re-raises the exception.

I created another PR here to illustrate this approach:

#7947

It's a valid approach, less hacky than the current PR, but user still needs to scroll up for worker info. This is what I meant when I said "but that still means any unhandled exception would not have worker info". The client logs worker info, but the exception thrown on the client doesn't have it:

---------------------------------------------------------------------------
BadNumbers                                Traceback (most recent call last)
Cell In[5], line 1
----> 1 client.submit(f).result()

Cell In[3], line 2, in f()
      1 def f():
----> 2     raise BadNumbers(1, 2.5, 3)

BadNumbers: I didn't like these numbers: 1.0 2.5 3.0

Maybe this is fine. I can go with #7947 too.

@j-bennet

Copy link
Copy Markdown
Contributor Author

Closing in favor of #7947.

@j-bennet j-bennet closed this Jul 20, 2023
@j-bennet
j-bennet deleted the j-bennet/4880-cleanup-remote-tracebacks branch July 20, 2023 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review Needs review from a contributor.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants