{"action":"closed","issue":{"url":"https://api.github.com/repos/zendesk/maxwell/issues/1137","repository_url":"https://api.github.com/repos/zendesk/maxwell","labels_url":"https://api.github.com/repos/zendesk/maxwell/issues/1137/labels{/name}","comments_url":"https://api.github.com/repos/zendesk/maxwell/issues/1137/comments","events_url":"https://api.github.com/repos/zendesk/maxwell/issues/1137/events","html_url":"https://github.com/zendesk/maxwell/issues/1137","id":372472223,"node_id":"MDU6SXNzdWUzNzI0NzIyMjM=","number":1137,"title":"JS Filters problem \"TypeError:is not an Object\"","user":{"login":"tomlis","id":6882447,"node_id":"MDQ6VXNlcjY4ODI0NDc=","avatar_url":"https://avatars0.githubusercontent.com/u/6882447?v=4","gravatar_id":"","url":"https://api.github.com/users/tomlis","html_url":"https://github.com/tomlis","followers_url":"https://api.github.com/users/tomlis/followers","following_url":"https://api.github.com/users/tomlis/following{/other_user}","gists_url":"https://api.github.com/users/tomlis/gists{/gist_id}","starred_url":"https://api.github.com/users/tomlis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomlis/subscriptions","organizations_url":"https://api.github.com/users/tomlis/orgs","repos_url":"https://api.github.com/users/tomlis/repos","events_url":"https://api.github.com/users/tomlis/events{/privacy}","received_events_url":"https://api.github.com/users/tomlis/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-10-22T10:45:32Z","updated_at":"2018-12-15T00:38:39Z","closed_at":"2018-12-15T00:38:39Z","author_association":"NONE","body":"I would like to use custom JS filters to truncate all hashes in \"data\" and \"old_data\" to certain length, for example max 2000 characeters. \r\n\r\nHere is code for filters: \r\n```\r\nfunction process_row(row) {\r\n  row.query = truncate_param(row.query, 3000, false);\r\n  truncate_object(row.data, 2000, true);\r\n  truncate_object(row.old, 2000, true);\r\n}\r\n\r\nfunction truncate_object(obj, maxLength, replaceNulls) {\r\n  Object.keys(obj).forEach(function (key) {\r\n    obj[key] = truncate_param(obj[key], maxLength, replaceNulls);\r\n  });\r\n}\r\n\r\nfunction truncate_param(param, length, replaceNulls) {\r\n  if (typeof param === 'string' || param instanceof String) {\r\n    return param.substring(0, length);\r\n  }\r\n  if (replaceNulls && param == null){\r\n    return '---empty---';\t\t\r\n  }\r\n  return param;\r\n}\r\n```\r\n\r\nI tested with using local env, runnig that script by\r\n\r\n>  node filters.js\r\n\r\n and giving as input an example row (output from prod's maxwell) like \r\n`\r\nvar row = {\"database\":\"xxx\",\"table\":\"yyy\",\"query\":\"..\r\nprocess_row (row);`\r\nand it seems to worked fine - it truncated all hashes in data and old_data (also replaced nulls with my string) \r\n\r\nHowever when run on production server with maxwell I get an errors: \r\n`<eval>:48 TypeError: {id=586845, status_id=74, order_id=22127, type=terg_wk, created_at=2018-10-17 15:38:14} is not an Object`\r\n\r\n\r\nFull error: \r\n```\r\n\r\nUsing kafka version: 1.0.0\r\n15:38:17,844 WARN  MaxwellMetrics - Metrics will not be exposed: metricsReportingType not configured.\r\n15:38:19,538 ERROR TaskManager - cause: \r\njdk.nashorn.internal.runtime.ECMAException: TypeError: {id=586845, status_id=74, order_id=22127, type=terg_wk, created_at=2018-10-17 15:38:14} is not an Object\r\n    at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57) ~[nashorn.jar:?]\r\n    at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:213) ~[nashorn.jar:?]\r\n    at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:185) ~[nashorn.jar:?]\r\n    at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:172) ~[nashorn.jar:?]\r\n    at jdk.nashorn.internal.objects.NativeObject.notAnObject(NativeObject.java:136) ~[nashorn.jar:?]\r\n    at jdk.nashorn.internal.objects.NativeObject.keys(NativeObject.java:439) ~[nashorn.jar:?]\r\n    at jdk.nashorn.internal.scripts.Script$Recompilation$3$1377AIZ$\\^eval\\_.truncate_object(<eval>:48) ~[?:?]\r\n    at jdk.nashorn.internal.scripts.Script$Recompilation$1$1182A$\\^eval\\_.process_row(<eval>:43) ~[?:?]\r\n    at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:639) ~[nashorn.jar:?]\r\n    at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) ~[nashorn.jar:?]\r\n    at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) ~[nashorn.jar:?]\r\n    at jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:117) ~[nashorn.jar:?]\r\n    at com.zendesk.maxwell.scripting.Scripting.invoke(Scripting.java:56) ~[maxwell-1.18.0.jar:1.18.0]\r\n    at com.zendesk.maxwell.replication.BinlogConnectorReplicator.work(BinlogConnectorReplicator.java:159) ~[maxwell-1.18.0.jar:1.18.0]\r\n    at com.zendesk.maxwell.util.RunLoopProcess.runLoop(RunLoopProcess.java:27) ~[maxwell-1.18.0.jar:1.18.0]\r\n    at com.zendesk.maxwell.Maxwell.startInner(Maxwell.java:224) ~[maxwell-1.18.0.jar:1.18.0]\r\n    at com.zendesk.maxwell.Maxwell.start(Maxwell.java:156) ~[maxwell-1.18.0.jar:1.18.0]\r\n    at com.zendesk.maxwell.Maxwell.main(Maxwell.java:245) ~[maxwell-1.18.0.jar:1.18.0]\r\n<eval>:48 TypeError: {id=586845, status_id=74, order_id=22127, type=terg_wk, created_at=2018-10-17 15:38:14} is not an Object\r\n    at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)\r\n    at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:213)\r\n    at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:185)\r\n    at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:172)\r\n    at jdk.nashorn.internal.objects.NativeObject.notAnObject(NativeObject.java:136)\r\n    at jdk.nashorn.internal.objects.NativeObject.keys(NativeObject.java:439)\r\n    at jdk.nashorn.internal.scripts.Script$Recompilation$3$1377AIZ$\\^eval\\_.truncate_object(<eval>:48)\r\n    at jdk.nashorn.internal.scripts.Script$Recompilation$1$1182A$\\^eval\\_.process_row(<eval>:43)\r\n    at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:639)\r\n    at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)\r\n    at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)\r\n    at jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:117)\r\n    at com.zendesk.maxwell.scripting.Scripting.invoke(Scripting.java:56)\r\n    at com.zendesk.maxwell.replication.BinlogConnectorReplicator.work(BinlogConnectorReplicator.java:159)\r\n    at com.zendesk.maxwell.util.RunLoopProcess.runLoop(RunLoopProcess.java:27)\r\n    at com.zendesk.maxwell.Maxwell.startInner(Maxwell.java:224)\r\n    at com.zendesk.maxwell.Maxwell.start(Maxwell.java:156)\r\n    at com.zendesk.maxwell.Maxwell.main(Maxwell.java:245)\r\n```\r\n\r\nWhats wrong ? "}}
{"actor":{"display_login":"osheroff"}}