Jason
Jason

Reputation: 14605

genstrings tool throwing exception, aborting when parsing XCode project

I've been using genstrings to build strings files to internationalize my iPhone app. However, some changes I made recently have caused the genstrings tool to start throwing errors like this:

s1075-88:Directory jason$ genstrings -o en.lproj *.m
2011-02-26 16:42:26.941 genstrings[17962:903] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFString characterAtIndex:]: Range or index out of bounds'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00007fff82a267b4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x00007fff85c640f3 objc_exception_throw + 45
    2   CoreFoundation                      0x00007fff82a265d7 +[NSException raise:format:arguments:] + 103
    3   CoreFoundation                      0x00007fff82a26564 +[NSException raise:format:] + 148
    4   Foundation                          0x00007fff841a65e1 -[NSCFString characterAtIndex:] + 97
    5   genstrings                          0x0000000100001b9d 0x0 + 4294974365
    6   genstrings                          0x0000000100003080 0x0 + 4294979712
    7   genstrings                          0x0000000100003ee6 0x0 + 4294983398
    8   genstrings                          0x0000000100000d20 0x0 + 4294970656
)

What could be causing this, and how can I find the part of my project which is causing it without manually changing everything?

Upvotes: 3

Views: 2365

Answers (7)

deltacrux
deltacrux

Reputation: 1326

This is the error that is generated when genstrings can't find the end of the macro call.

Note that the genstrings utility can't handle calls that span multiple lines (regardless of whether there is a comment inside or not).

So this works:

NSLocalizedString(@"Key", @"Comment")

but this doesn't

NSLocalizedString(@"Key",
                  @"Comment")

Upvotes: 0

Mikael
Mikael

Reputation: 2395

having Swift 4

"""
This is a comment
"""

syntax seems to make it crash too.

Upvotes: 0

Yoav
Yoav

Reputation: 6108

For me it crashed due to a comment inside an NSLocalizedString call.

For example:

NSLocalizedString(@"some text" /* a comment */,  
                  @"some other text.");

causes crashes genstrings, but this is fine:

/* a comment */
NSLocalizedString(@"some text", @"some other text.");

Upvotes: 0

smileyborg
smileyborg

Reputation: 30479

I ran into this issue. In my case, genstrings was scanning <filename>.m.orig files left over from a git merge. Deleting the *.m.orig files fixed things, as they must have contained malformed localized strings.

Upvotes: 0

ray
ray

Reputation: 11

In case it helps anyone else, I got this crash when having an NSLocalizedString in a comment. I guess it found it and it didn't have parameters and crashes

Upvotes: 1

fabian789
fabian789

Reputation: 8412

You could limit the numbers of file processed by genstrings by using head. If this is your command to localize all files:

find . -name \*.m | xargs genstrings -o en.lproj

Then this is how it looks like when using head:

find . -name \*.m | head -5 | xargs genstrings -o ~/Documents/GenStringsTest

Just increase the number next to head and run the command again and again, until it crashes. Between runs, you can delete the files in the temporary GenStrinsTest folder. When it crashes, decrease the number until you now exactly where it crashes and then run

find . -name \*.m | head -<minimum number of files for crash>

and the last file that will be written on the console will be the "wrong" one.

Upvotes: 2

amattn
amattn

Reputation: 10065

No easy tricks here.

copy all your .m files to a separate folder then do a binary search.

run genstrings on half the files and see if the problem is there or not. isolate which half of the files have the problem and do it again...

It's a bug inside genstrings, so not much you can do about it.

Upvotes: 3

Related Questions