Forum Discussion

jpsheff's avatar
jpsheff
New Contributor
6 years ago

Escaping Single Quotes in Error Pipeline - Issue

Fairly new SL user here.

I am in the process of creating an error pipeline to handle system generated errors that may occur in our pipelines.

In this error pipeline we capture the error, error reason, error resolution, snap name, and the original record name/value pairs for all fields on the record that failed to load.

We capture this information from the error response JSON array passed from the failed parent pipeline to the error pipeline. See example:

[
{
        "error": "Cannot invoke toExponential() on a function",
        "stacktrace": "com.snaplogic.snap.api.SnapDataException: Cannot invoke toExponential() on a function\n\tat sl.EvaluatorUtils.methodInternal(EvaluatorUtils.java:903)\n\tat sl.EvaluatorUtils.method(EvaluatorUtils.java:765)\n\tat SC.evaluate(Unknown Source)\n\tat com.snaplogic.util.ExpressionUtils$MyExpressionProperty.eval(ExpressionUtils.java:243)\n\tat com.snaplogic.snap.api.impl.PropertyValuesImpl$ValidatingExpressionProperty.eval(PropertyValuesImpl.java:989)\n\tat com.snaplogic.snaps.transform.DataTransform.processBinary(DataTransform.java:265)\n\tat com.snaplogic.snaps.transform.DataTransform.process(DataTransform.java:218)\n\tat com.snaplogic.snap.api.ExecutionUtil.process(ExecutionUtil.java:106)\n\tat com.snaplogic.snap.api.ExecutionUtil.executeForDocument(ExecutionUtil.java:118)\n\tat com.snaplogic.snap.api.ExecutionUtil.execute(ExecutionUtil.java:81)\n\tat com.snaplogic.snap.api.SimpleSnap.execute(SimpleSnap.java:70)\n\tat com.snaplogic.cc.snap.common.SnapRunnableImpl.executeSnap(SnapRunnableImpl.java:768)\n\tat com.snaplogic.cc.snap.common.SnapRunnableImpl.execute(SnapRunnableImpl.java:550)\n\tat com.snaplogic.cc.snap.common.SnapRunnableImpl.doRun(SnapRunnableImpl.java:834)\n\tat com.snaplogic.cc.snap.common.SnapRunnableImpl.call(SnapRunnableImpl.java:400)\n\tat com.snaplogic.cc.snap.common.SnapRunnableImpl.call(SnapRunnableImpl.java:116)\n\tat java.base/java.util.concurrent.FutureTask.run(Unknown Source)\n\tat java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)\n\tat java.base/java.util.concurrent.FutureTask.run(Unknown Source)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\n\tat java.base/java.lang.Thread.run(Unknown Source)\n",
        "reason": "Functions only have an apply() method",
        "resolution": "Please check expression syntax and data types.",
        "status_code": "error",
        "snap_details": {
            "label": "Mapper",
            "instance_id": "1abcdefg2-abc-123a-123b-123abc123abc",
            "class_id": "com-snaplogic-snaps-transform-datatransform",
            "build_tag": "snaps12345",
            "views": {
                "in": {
                    "input0": {
                        "count": 267
                    }
                },
                "out": {
                    "output0": {
                        "count": 0
                    }
                },
                "error": {
                    "error0": {
                        "count": 266
                    }
                }
            }
        },
        "original": {
            "value": 1266,
            "field1": "123456",
            "field2": "NEW YORK",
            "field3": "NY",
            "field4": "12345",
            "field5": "16:00:01",
            "field6": "AUTOMATION TEST CLIENT",
            "field8": "123 SESAME ST",
            "field9": "",
            "field10": "",
            "field11": "12/02/2019 00:00:00",
            "field12": "12/03/0001 00:00:00",
            "field13": "",
            "field14": "0",
            "field15": "0",
            "field16": "",
            "field17": "",
            "field18": "",
            "field19": "M",
            "field20": "3",
            "field21": "SOMEUSR",
            "field22": "Elmo's Burgers"
        }
    }
]

Currently I am having an issue with escaping special characters - specifically single quotes (') that are received in the name value pairs for the original. See field 22 in the above example.

I have attempted the following to remove them using the replace function:

When replace or replaceAll is applied to the $reason and $resolution fields, the single quotation is escaped when we receive them, however when $original.replaceAll(“'”,“‘’”) is used single quotes are not escaped - same results when using JSON.stringify($original).replaceAll(“'”,“‘’”).

Any advice on how to escape these single quotes would be greatly appreciated.

3 Replies

  • dimche_saveski's avatar
    dimche_saveski
    New Contributor III

    Hello @jpsheff
    If you want to replace the single with double quotes, Spiro’s example is great.
    But if you trying to replace single quote with empty space, you can use replace method with a regex like this

    Best Regards
    Dimche

  • jpsheff's avatar
    jpsheff
    New Contributor

    @Spiro_Taleski and @dimche.saveski thank you both for your responses. Ultimately JSON.stringify($original).replace( /'/g,“‘’”) fit the bill, as my target was a JSON defined field on a table.