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

ptaylor
Employee
Employee

Yes, we still use the Nashorn engine for JavaScript. It’s deprecated but still present in Java 11.

I can’t speak to how anyone debugs their JS scripts.

Thanks for the rapid reply!

I’m hoping that a long-term Snaplogic user might chirp up with some phenomenally useful tricks that let me find problem code in our JS snaps and fix it.

For most transformations, the SnapLogic expression language can be used. We support dynamic validations, which enables rapid prototyping and development.

For more complex requirements, a custom Snap can be developed in Java. Full IDE support is possible through debugger support. A custom snap has performance advantages over a Script snap when the document count is large, but the development of the custom snap does require more effort.

For the Script snap, using log statement to debug the script is one approach. Another approach is to develop the script outside of SnapLogic, using the command-line version of the language to test the script and then upload the script into SnapLogic. This works well for Jython, I believe the same approach works for JavaScript.

Is there some other kind of logging available in JS besides adding extra “trace” properties to docs in the document stream?