Have you read the Acrobat JS API Reference about the insertPages and the path value and restrictions?
insertPages now needs to use the "privileged context" when not being run as a console or batch event.
A path cannot point to a system critical folder, for example a root, windows or system directory. A path is also subject to other unspecified tests.
For many methods, the file name must have an extension appropriate to the type of data that is to be saved. Some methods may have a no-overwrite restriction. These additional restrictions are noted in the documentation.
Generally, when a path is judged to be not safe, a NotAllowedError exception is thrown (see Error object) and the method fails.
This can't be the reason, or it wouldn't have worked at all... The fact that it inserts a couple of pages and then stops suggests to me that its an issue with one of the page number variables.
What is even more strange is I made a 9 page test pdf (and obviously copied this test pdf and named the copy source)... I ran the same exact code... It gives me a 27 page pdf and functions as intended, yet pops up an error code:
TypeError: Invalid argument type.
- Doc.insertPages:9:Batch undefined:Exec
===> Parameter nPage.
I have to imagine this has to do with the fact that this document is only 9 pages when it is expecting to run the loop 200 times.
After inserting dialog printlns all over the place to test what is doing when exactly, and where it is failing, I've established that it loops through once as normal, gets to the second loop through, inserts page 2 of the source, then fails (hence getting to 203 pages overall) but I don't get why (and what is different from the 9 page test). Curiously, I have a println right after each page is inserted, and it doesn't even get to that print ln after the first page 2 is inserted. So it inserts that page 2, then fails and doesn't even try on the second page 2 insert.
I would suggest you try debugging it. For example by writing out to the console the values of sourcepage and targetpage and making sure they are what they need to be.
By the way, how many pages are there in the "source.pdf" file?