cancel
Showing results for 
Search instead for 
Did you mean: 

Debugging Javascript - General Guidance

ForbinCSD
Contributor

I’m looking for General Guidance, not a solution to a specific problem!

I have a lot of experience programming in server-side languages like C++, C#, T-SQL, PL/SQL, and others… but am very much a newbie at Javascript. (When my employers’ pipelines use a Script snap, we solely use Javascript, not Python nor Ruby.)

How do other Snaplogic users debug the JS in their script snaps?

I’ve been largely just writing the equivalent of “print” statements by creating a debug object or a set of “trace” properties in the document stream. But that’s a rather hamfisted and slow-going method for debugging.

I seem to recall that SnapLogic uses (used?) the Nashorn engine, but now that Snaplexes are on Java 11, is that still true? There’s the “NCDbg” project on GitHub, which provides a debugger for Nashorn that can connect to Visual Studio Code (VSCode) as a front-end… but it can only handle JS atop an underlying Java 8 or 9 JVM. I’m wondering if there is something similar that would match up more closely with the SnapLogic engines and environment.

What do the rest of you do when you want to debug a script snap?

Thanks!

6 REPLIES 6

Thanks, AkiDave. I think of the three options you present, only the third pair are viable: logging and/or externally debugging. If I’m troubleshooting someone else’s implementation of XTEA (or something else not built into Snaplogic), for example, I’m not going to be able to break that into expressions in a mapping snap. And I don’t have the budget to sidetrack an entire developer for a while and have them learn to implement a custom debugging snap — we would have done that long ago if we had known that was going to be something we needed.

So I’m hoping that another pipeline developer (customer or SnapLogic) who’s done this can chip in and advise me how to set up an external debugging environment. (This would speed up things for me wonderfully.) I’ve been trying to set up NCDbg and Nashorn atop the same Java 11 distro that we use in the Snaplex, but the documentation is sorely lacking and assumes a lot of infrastructure knowledge that I just don’t have. Instructions like “just run the engine like you normally do and pass the same configuration parameters you used there also over here but with so-and-so modified.” Okay, if I’ve never run the JVM stand alone and also never a JS engine on top of that, and also the debugger components, there is no “usually,” LOL.

ForbinCSD
Contributor

@ptaylor or @akidave -

I’ve been able to do a little experimentation using Microsoft Visual Studio Code using its built-in JS debugger. And I think one of my colleagues may be close to getting it to work with NCDbg + Nashorn + Java11 (same JVM distro our GroundPlexes use).

But it requires commenting out a LOT of the SnapLogic infrastructure so that what one is debugging is only marginally like the code that gets executed in the Snap.

In particular, it would be helpful to be able to fake a doc stream, and to be able to instantiate a copy of “impl” and debug the execute method. But that requires fake versions of (input,output,error,log).

Can you please ask around within Development about this? I imagine someone there might have built some scaffolding or a test jig where they could run a script externally with some faked inputs.

For that matter, since we’re exclusively on GroundPlexes, and the WAR files are right there, I imagine there might even be a way to import some of that?

Thanks!!
@ForbinCSD aka JohnB