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

Trying to open a non-existant .po file gives incorrect error #134

Open
boxed opened this issue Feb 12, 2023 · 3 comments
Open

Trying to open a non-existant .po file gives incorrect error #134

boxed opened this issue Feb 12, 2023 · 3 comments

Comments

@boxed
Copy link

boxed commented Feb 12, 2023

                raise IOError('Syntax error in po file %s(line %s)' %
                              (fpath, self.current_line))

but in fact the file doesn't exist.

@kthy
Copy link
Contributor

kthy commented Feb 14, 2023

The problem here is that polib can both parse a string directly, or read a file and parse its contents. If the input is not an existing file (polib.py line 1266), it assumes that input is a string and tries to parse it, hence the error message you're seeing.

"Fixing" the error message would mean guessing that the input looks path-like and giving the user feedback to that effect.

@boxed
Copy link
Author

boxed commented Feb 14, 2023

Hmm.. well that's unfortunate. I guess the real fix is to have different arguments for path and for a string. But the error message could at least say "The file does not exist, or there's a syntax error" or something. It's not great, but it's at least not a lie.

@rillig
Copy link

rillig commented Feb 23, 2024

@kthy What about assuming that if the string contains a line break, it is meant as direct text, and in all other cases it's a filepath? This simple rule would get the error message from "always wrong" to "wrong in probably less than 1/10000 cases".

I don't think there are practical use cases where a file is named msgid "".po.

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

No branches or pull requests

3 participants