Possibly, depending on what you want to happen. You could encase the toWorldVec() in a try/catch clause, but then you have to decide what you want the result to be in that case:
try{
thisComp.layer(2).toWorldVec([1,0,0])
}catch(e){
[1,0,0]
}
Or maybe you could have an invisible layer that isn’t scaled parented to the layer that is scaled and get the x vector from the one that isn’t scaled. It depends on what your situation is.