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

nav() now displays some debugging information on KeyError #540

Merged
merged 5 commits into from
Mar 1, 2024

Conversation

linsomniac
Copy link
Contributor

There's a user reporting a KeyError in nav(), so I've changed it to print out the key and dict for future debugging. Also, a bare Exception was used to capture a dictionary failure, removed that since my change checks for the existence of the key in the dictionary. If this is objectionable at all, you probably should change it to catching a KeyError rather than catching Exception.

This is to gather information for #539

There's a user reporting a KeyError in nav(), so I've changed it to
print out the key and dict for future debugging.  Also, a bare
Exception was used to capture a dictionary failure, removed that
since my change checks for the existance of the key in the dictionary.
If this is objectionable at all, you probably should change it to
catching a KeyError rather than catching Exception.
@sigma67 sigma67 linked an issue Feb 13, 2024 that may be closed by this pull request
@sigma67
Copy link
Owner

sigma67 commented Feb 13, 2024

Did you test this change?

nav has more than 250 usages across the project, it's not something to change as a drive-by

Simply running the get_album tests fails instantly - you didn't consider that items may contain integer indices

Sean Reifschneider added 2 commits February 14, 2024 07:51
This goes back to catching exceptions because the `root` can also
be a list during the loop lifetime.  Narrowed down to KeyError
and IndexError exceptions, enrich the exception msg with details
about the failure.
To make for an easier review, I've restructured the nav() change
to more closely match the original.
@linsomniac
Copy link
Contributor Author

I couldn't originally get the tests working, I believe this change addresses that problem.

@linsomniac linsomniac closed this Feb 14, 2024
@linsomniac linsomniac reopened this Feb 14, 2024
@sigma67
Copy link
Owner

sigma67 commented Feb 14, 2024

Sorry, it still doesn't work.

TypeError: 'NoneType' object is not subscriptable

Missed a failing test, having to catch TypeError as well.
Also realized that I need the try/catch in the loop since it
uses the value of "k" in the information message.
@linsomniac
Copy link
Contributor Author

Sorry for the delay in getting back to this, busy end of the week. I missed that exception, thanks for pointing it out. I think this modification resolves that issue.

One issue I'm running into that perhaps you can help with is that I'm getting a bunch of config-related test failures, and I didn't see that None error among those other ones. The test instructions say to run: cp tests/test.example.cfg tests/test.cfg, but the repo doesn't seem to have a "test.example.cfg" file in it, or any "cfg" file AFAICT.

@sigma67
Copy link
Owner

sigma67 commented Feb 22, 2024

Sorry about the test.cfg issue, I accidentally deleted the file instead of renaming it due to the presence of a gitignore on **.cfg

@sigma67
Copy link
Owner

sigma67 commented Feb 22, 2024

What's the advantage of moving the try-except inside the loop? Isn't that even more overhead?

@linsomniac
Copy link
Contributor Author

Having it in the loop means it has access to the value of "k" to be able to log. It could be moved outside the loop but would lose that data, but might still provide enough information to track down, given more effort.

@sigma67
Copy link
Owner

sigma67 commented Feb 23, 2024

But it's bad: https://docs.astral.sh/ruff/rules/try-except-in-loop/

And with nav it matters, because it's used a lot.

@linsomniac
Copy link
Contributor Author

[I] sean@seans-laptop ~/p/realgoansible (master)> python3 -m timeit 'for x in range(10):' '   y = x + 1'
2000000 loops, best of 5: 199 nsec per loop
[I] sean@seans-laptop ~/p/realgoansible (master)> python3 -m timeit 'for x in range(10):' '   try:' '      y = x + 1' '
except:' '      pass'
1000000 loops, best of 5: 202 nsec per loop

LSP is telling me that "k is unbound" if I move the try/except out of the loop, but if I run a test I am getting the loop variable past the loop:

try:
    for x in [1,2,3,4]:
        if x == 3:
            1 / 0
except Exception as e:
    print(f"Failed, {x}")

Results in: "Failed, 3".

So, I've moved it out of the loop.

@sigma67 sigma67 merged commit 13701c4 into sigma67:main Mar 1, 2024
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.

KeyError 'runs' on get_library_playlists()
2 participants