-
Notifications
You must be signed in to change notification settings - Fork 742
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
TypeError: %b requires a bytes-like object, or an object that implements __bytes #630
Comments
I just ran into this too, looks like it's user error. The callback functions need to return byte-strings. From the man page:
In my case, I had to use To the maintainers: perhaps git-filter-repo could produce a friendlier error message in cases like this? For example, in Alternatively, git-filter-repo could check if the callbacks return a |
You didn't specify your email callback, but I suspect you forgot to include a
Thanks for commenting; my guess from the error they got is actually that they forgot the
maintainer, actually. There's just one of me. Anyway... For callbacks like name, filename, message, email, or refname, it might be simple -- though potentially expensive since the callbacks are called so many times. And what about cases like commit or tag callbacks? Do we have to check every field of the resulting object that was operated on, since there's no way to know which field might have been modified? And do so every time the callback is called? While I like the idea of friendlier messages, I don't like the idea of introducing such overhead. |
Ah yeah, probably. I mainly saw the approximately-same stack trace here when I went searching for issues. Somewhere along the line seeing the phrase "bytes-like object" jogged my memory enough to remember the byte-strings requirement. My instinct was that a check along the lines wouldn't be too expensive, but python performance characteristics can be weird. It'd also be a lot of refactoring because as you mention there's a lot of callback fields. thing = self._thing_callback(thing)
if not hasattr(thing, '__bytes__'):
raise SomeError(f'be sure return byte-strings from callbacks, not {type(thing)}') Maybe exception handling would be easier and faster - catch a Maybe something like this would work? Or maybe localization prevents properly reading the message like this... filter = RepoFilter(args)
try:
filter.run()
except TypeError as err:
if 'bytes-like object' in str(err):
print('NOTE: callback functions must return bytestrings, not str')
raise
Thank you for your time spent making this tool :) |
I didn't expect each individual check to be expensive; rather, the sheer number of checks is my primary concern. I am worried about the number of codepaths that would need to be modified as well, but doing the checks for every commit (or multiple times per commit for e.g. name or email checks) is my bigger worry. Also, this code example you provide only works for name, email, message, and filename callbacks. Other callbacks like commit and tag don't return an object but potentially mutate one of the arguments passed, and that argument has lots of subfields, most of which need to be byte-strings, so any commit callback for example would result in the need for several checks for each invocation of the callback.
This assumes that (a) the user returned a str (which isn't even valid for this bug report; from the error we see that they returned a NoneType, not a string, so your note would have been misleading for them), (b) the user is only using callbacks which are supposed to return something (not all callbacks are designed that way; see the commit and tag callbacks for example) -- though a slight rewording of the note might be able to address this, (c) the "bytes-like object" error triggered in the code was due to a callback function: there have been other "bytes-like object" errors triggered in the past outside of user (or script) callbacks in the past which can be found in this bug tracker, and I think this message could potentially be confusing to users if it were to be shown in such a case. It does have the appeal of being simple and a small code change, so maybe there's a tweak of an idea here that might help. I'll leave it open for now...
I'm glad you like the tool. :-) |
For
--force --refs "staging~17"..staging --email-callback '...'
The text was updated successfully, but these errors were encountered: