kronenthaler/mod-pbxproj

[BUG] Error in openstep_parser: string index out of range

VitorMMOliveira opened this issue · 6 comments

Describe the bug
I'm trying to use the default sample code on the homepage just to check how mod-pbxproj works, however I stumbled upon this error:

Traceback (most recent call last):
File "xcode_python_setup.py", line 3, in
project = XcodeProject.load('../myapp/myapp.xcodeproj/project.pbxproj')
File "/Library/Python/2.7/site-packages/pbxproj/XcodeProject.py", line 90, in load
tree = osp.OpenStepDecoder.ParseFromFile(open(path, 'r'))
File "build/bdist.macosx-10.15-x86_64/egg/openstep_parser/openstep_parser.py", line 42, in ParseFromFile
File "build/bdist.macosx-10.15-x86_64/egg/openstep_parser/openstep_parser.py", line 46, in ParseFromString
File "build/bdist.macosx-10.15-x86_64/egg/openstep_parser/openstep_parser.py", line 51, in _parse
IndexError: string index out of range

System information

  1. pbxproj version used: 3.2.0
  2. python version used: 3.6.12
  3. Xcode version used: 12.0 (12A7209)

To Reproduce
Steps to reproduce the behavior:

  1. Created a .py file with this code

from pbxproj import XcodeProject
project = XcodeProject.load('../myapp/myapp.xcodeproj/project.pbxproj')
project.save()

  1. On the terminal, cd to a related folder and ran: "python xcode_python_setup.py"
  2. See error

Expected behavior
Just expected to see a clear python command without any errors.

Thanks for your report

Looking at the stacktrace it may seem that the wrong python package is running, the python 2.7 version of it.

File "/Library/Python/2.7/site-packages/pbxproj/XcodeProject.py", line 90, in load
tree = osp.OpenStepDecoder.ParseFromFile(open(path, 'r'))

In the code, the line 90 is something else:

targets = self.objects.get_targets(name)

Double check by installing the package using pip3 and running it with python3 command.

Thank you for getting back to me.

I ran the same script with python3 this time, after installing the package with pip3:

Traceback (most recent call last):
  File "/Library/Python/3.8/site-packages/pbxproj/XcodeProject.py", line 103, in load
    tree = osp.OpenStepDecoder.ParseFromFile(file)
  File "/Library/Python/3.8/site-packages/openstep_parser/openstep_parser.py", line 40, in ParseFromFile
    return cls.ParseFromString(fp.read())
  File "/Library/Python/3.8/site-packages/openstep_parser/openstep_parser.py", line 46, in ParseFromString
    return OpenStepDecoder()._parse(str)
  File "/Library/Python/3.8/site-packages/openstep_parser/openstep_parser.py", line 51, in _parse
    if str[0] == '/' and str[1] == '/':
IndexError: string index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "xcode_python_setup.py", line 3, in <module>
    project = XcodeProject.load('../myapp/myapp.xcodeproj/project.pbxproj')
  File "/Library/Python/3.8/site-packages/pbxproj/XcodeProject.py", line 107, in load
    return XcodeProject(plistlib.load(file), path)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/plistlib.py", line 986, in load
    raise InvalidFileException()
plistlib.InvalidFileException: Invalid file

Thanks for trying out.

Could you share the sample project to check it manually? I'd only need the project.pbxproj file.

Sorry, unfortuntely I can't due to NDAs.

But maybe I could check it on my machine if I have the instructions, and then share the results here.

Understood.

Index out of range would point me to the end of the file. It looks like a unclosed something, or a broken comment.

Solved! Thanks for the input.

I checked the pbxproj file and it was empty. Probably due to some other error in the past.
I just reverted the changes on git and it works fine now with python3. Thank you for the support!