I agree that the official documentation on using Action Manager in javascript is poor to non-existent so your best source is the user forums. I think PS-Scripts is better but I'll admit to being biased about that.
If you wanted to reference a layer by name and the code you have references by index and you have a line that reads
ref.putIndex( charIDToTypeID( 'Lyr ' ), i );// class,index property
If you look in the javascript reference under ActionReference you see that putIndex has two arguments. The first is the class and the second it the index as a number. The charID 'LyrN' does map to the stringID 'layerName'. But name is a property so would be used where a class ID is required. Instead you change the method to putName and it will use the name instead of the index.
ref.putName( charIDToTypeID( 'Lyr ' ), layerNamei );// class,name properry
Making a guess about which ID to use is never a good idea but I will admit that I have done that more than once.
It is also true that the error messages are long longer very helpful. At one time Photoshop did have much better error messages for what caused the error. Not they might as well just say 'Error'.