Skip to content

Added TypeError excception catcher#183

Open
spacewalrus73 wants to merge 7 commits intogicait:masterfrom
spacewalrus73:fix-exception-in-supports
Open

Added TypeError excception catcher#183
spacewalrus73 wants to merge 7 commits intogicait:masterfrom
spacewalrus73:fix-exception-in-supports

Conversation

@spacewalrus73
Copy link
Copy Markdown

No description provided.

@iboates
Copy link
Copy Markdown
Collaborator

iboates commented Aug 22, 2025

Can you give an explanation as to what this is solving? If it is a TypeError then I would think that whatever is being passed is not a string and you would still have a problem

@spacewalrus73
Copy link
Copy Markdown
Author

spacewalrus73 commented Aug 25, 2025

Can you give an explanation as to what this is solving? If it is a TypeError then I would think that whatever is being passed is not a string and you would still have a problem

Hi, sorry i forgot to write comment. Thank you for the question. This specifically addresses when users pass Path objects instead of strings. Without this catch, the TypeError prevents the code from reaching the Path(path).exists() check that would properly handle these objects. The fix maintains the intended workflow while preserving the original validation logic.
I know that i can use Path.resolve() to get string and then it will right. May be comment in method docstring confused me. 'Path to the style file or XML string.' and i decided to fix it. Maybe I should have stated the problem first, sorry again. This is my first pull request.
Thank you for your contribution to the community and I hope to be of service

@iboates
Copy link
Copy Markdown
Collaborator

iboates commented Aug 26, 2025

Thanks for the explanation, it's more clear now. In this case, would suggest adding a separate check to explicitly check if it is a Path object, and return false if it is. I think that is more robust than assuming that any TypeError is an indication of whether or not it is parsable XML.

Indeed the name of the parameter path is a bit of a misnomer due to also accepting an XML string. It used to expect only a file path, but was changed to allow XML strings in order to not require saving anything to disk or messing about with a MemoryFile. The name was kept the same in order to not break existing code.

Thanks for your interest and contribution.

Балабанов Даниил Александрович added 2 commits August 26, 2025 09:08
@spacewalrus73
Copy link
Copy Markdown
Author

Yes, that's a good idea, but I found a simpler way to fix it. Just changing the order of if checks inside the 'upload_style' method. It seems to have solved the problem of passing just 'Path' and works correctly when passing a string. Less code - less problems. I've committed the changes, hopefully this solution will work for you. Thanks!

@iboates
Copy link
Copy Markdown
Collaborator

iboates commented Aug 27, 2025

It's not a bad idea in theory but we had it this way before, I'm pretty sure, and there was a major problem with Windows systems due to a 255-character limit on file names. If you then pass the XML string (which is almost certainly more than 255 characters), it will fail because of this limitation.

@spacewalrus73
Copy link
Copy Markdown
Author

spacewalrus73 commented Aug 27, 2025

Ok, I couldn't reproduce the error you're talking about. Anyway, just added the Path check you mentioned above, and a test for it.

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.

2 participants