cancel
Showing results for 
Search instead for 
Did you mean: 

Escaping Single Quotes in Error Pipeline - Issue

jpsheff
New Contributor

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:

escape_char_issue_mapper

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 3

SpiroTaleski
Valued Contributor

Hi @jpsheff,

I suppose that you are trying to replace single quotes with double quotes.

I have built one simple pipeline containing the expression for replacing the single quotes in the original object.

SingleQuote_Issue_2020_03_31.slp (3.8 KB)

Please take a look on the attached pipeline, and let me know if this will resolve the issue.

Regards,
Spiro

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 Screenshot_2

Best Regards
Dimche

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.