error in mule 4 "You cannot compare a value of type :Null" - mule-component

I am trying to find the max of date from json data. But i am getting below error
Message : "You cannot compare a value of type :Null
Trace:
at reduce (Unknown)
at dw::Core::maxBy (line: 5535, column: 3)
at main (line: 1, column: 248)" evaluating expression:
"%dw 2.0 output application/json --- { Value2: ( if (vars.data.Value1 as String != "")
(payload maxBy((item) -> item.startDate)).startDate default vars.data.Value1
else "" ), RCount: sizeOf(payload) }".
Error type : MULE:EXPRESSION
Element : executeInterface/processors/8 # gg:gg.xml:121 (interface)
Element XML : <set-variable value="#[%dw 2.0 output application/json ---
{ Value2: ( if (vars.data.Value1 as String != "")
(payload maxBy((item) -> item.startDate)).startDate default vars.data.Value1
else "" ), RCount: sizeOf(payload) }]" doc:name="interface" doc:id="2c140185-2fc5-4e11-9b78-96fc2ddcfa2f" variableName="interface"></set-variable>
(set debug level logging or '-Dmule.verbose.exceptions=true' for everything).
The logic written in set variable component is
%dw 2.0
output application/json
---
{
Value2:
( if (vars.data.Value1 as String != "")
(payload maxBy((item) -> item.startDate)).startDate default vars.data.Value1
else ""
),
RCount: sizeOf(payload)
}
while running in the debug mode, found the problem is in maxby statement.
Please suggest.how to fix this issue

The error indicates that something is null when trying to compare. Given that you mentioned the error is at maxBy(), it is probable the the attribute startDate is null or not present in one of the elements. You should show also the values of the transformation so we could confirm it.
UPDATE: I can reproduce the error if the startDate attribute is not present or if it is misspelled. For example if I misspell item.StartDate (wrong uppercase 'S') it produces the error. Make sure the payload and script match exactly.

Related

Can a logstash filter error be forwarded to elastic?

I'm having these json parsing errors from time to time:
2022-01-07T12:15:19,872][WARN ][logstash.filters.json ] Error parsing json
{:source=>"message", :raw=>" { the invalid json }", :exception=>#<LogStash::Json::ParserError: Unrecognized character escape 'x' (code 120)
Is there a way to get the :exception field in the logstash config file?
I opened the exact same thread on the elastic forum and got a working solution there. Thanks to #Badger on the forum, I ended up using the following raw ruby filter:
ruby {
code => '
#source = "message"
source = event.get(#source)
return unless source
begin
parsed = LogStash::Json.load(source)
rescue => e
event.set("jsonException", e.to_s)
return
end
#target = "jsonData"
if #target
event.set(#target, parsed)
end
'
}
which extracts the info I needed:
"jsonException" => "Unexpected character (',' (code 44)): was expecting a colon to separate field name and value\n at [Source: (byte[])\"{ \"baz\", \"oh!\" }\r\"; line: 1, column: 9]",
Or as the author of the solution suggested, get rid of the #target part and use the normal json filter for the rest of the data.

The "error_marshaling_enabled" setting seems to be always enabled

When I run this code:
$client->evaluate('
box.session.settings.error_marshaling_enabled = false
box.error{code = 42, reason = "Foobar", type = "MyError"}
');
regardless of the value of error_marshaling_enabled I always get a response with a new (extended) error format:
[
49 => 'Foobar',
82 => [
0 => [
0 => [
0 => 'CustomError',
2 => 3,
1 => 'eval',
3 => 'Foobar',
4 => 0,
5 => 42,
6 => [
'custom_type' => 'MyError',
],
],
],
],
],
Why is that?
Short answer.
error_marshaling_enabled option affects only how error objects are encoded in response body (48, IPROTO_DATA). It does not affect how they are returned as exceptions, in the response header (82, IPROTO_ERROR).
Long answer.
In Tarantool an error object can be returned in 2 ways: as an exception and as an object. For example, this is how to throw an error as exception:
function throw_error()
box.error({code = 1000, reason = "Error message"})
-- Or
error('Some error string')
end
This is how to return it as an object:
function return_error()
return box.error.new({code = 1000, reason = "Error message"})
end
If the function was called remotely, using IPROTO protocol via a connector like netbox, or PHP connector, or any other one, the error return way affects how it is encoded into MessagePack response packet. When the function throws, and the error reaches the top stack frame without being caught, it is encoded as IPROTO_ERROR (82) and IPROTO_ERROR_24 (49).
When the error object is returned as a regular value, not as an exception, it is encoded also as a regular value, inside IPROTO_DATA (48). Just like a string, a number, a tuple, etc.
With encoding as IPROTO_ERROR/IPROTO_ERROR_24 there is no much of a configuration space. Format of these values can't be changed. IPROTO_ERROR is always returned as a MessagePack map, with a stack of errors in it. IPROTO_ERROR_24 is always an error message. The IPROTO_ERROR_24 field is kept for compatibility with connectors to Tarantool versions < 2.4.1.
With encoding as a part of IPROTO_DATA you can choose serialization way using error_marshaling_enabled option. When it is true, errors are encoded as MessagePack extension type MP_EXT, and contain the whole error stack, encoded exactly like IPROTO_ERROR value. When the option is false (default behaviour in 2.4.1), the error is encoded as a string, MP_STR, which is the error's message. If there is a stack of errors, only the newest error is encoded.
error_marshaling_enabled option exists for backward compatibility, in case your application on Tarantool wants to be compatible with old connectors, which don't support MP_EXT encoded errors.
In Tarantool < 2.4.1 errors were encoded into result MessagePack as a string with error message, and error stacks didn't exist at all. So when the new format and the error stacks feature were introduced, making the new format default would be a too radical change breaking the old connectors.
Consider these examples of how error marshaling affects results. I use Tarantool 2.4.1 console here, and built-in netbox connector. The code below can be copy pasted into the console.
First instance:
box.cfg{listen = 3313}
box.schema.user.grant('guest', 'super')
function throw_error()
box.error({code = 1000, reason = "Error message"})
end
function return_error()
return box.error.new({code = 1000, reason = "Error message"})
end
Second instance:
netbox = require('net.box')
c = netbox.connect(3313)
Now I try to call the function on the second instance:
tarantool> c:call('throw_error')
---
- error: Error message
...
The c:call('throw_error') threw an exception. If I catch it using pcall() Lua function, I will see the error object.
tarantool> ok, err = pcall(c.call, c, 'throw_error')
tarantool> err:unpack()
---
- code: 1000
base_type: ClientError
type: ClientError
message: Error message
trace:
- file: '[string "function throw_error()..."]'
line: 2
...
As you can see, I didn't set error_marshaling_enabled, but got the full error. Now I will call the other function, without exceptions. But the error object won't be full.
tarantool> err = c:call('return_error')
tarantool> err
---
- Error message
...
tarantool> err:unpack()
---
- error: '[string "return err:unpack()"]:1: attempt to call method ''unpack'' (a nil
value)'
...
The error was returned as a mere string, error message. Not as an error object. Now I will turn on the marshaling:
tarantool> c:eval('box.session.settings.error_marshaling_enabled = true')
---
...
tarantool> err = c:call('return_error')
---
...
tarantool> err:unpack()
---
- code: 1000
base_type: ClientError
type: ClientError
message: Error message
trace:
- file: '[C]'
line: 4294967295
...
Now the same function returned the error in the new format, more featured.
On the summary: error_marshaling_enabled affects only returned errors. Not thrown errors.

Can't remove Null terminator from byte array?

I'm using this library in Go (on OSX) to interact with a windows DNS server.
When running the below snippet, I get an error about a null terminator.
$ ~/go/bin/winrm-dns-client create -d domain.com -n node-0 -t A -v 10.90.61.30
2018/06/03 12:40:22 Error creating DNS record: Reading record: Reading record: Unmarshalling response: Unmarshalling json: invalid character '\x00' after array element
My suspicion is that there's a null terminator added here when the helper method calls sprintf to concat json responses into an array.
However, even after adding a bytes.Trim like shown below... I still get a null terminator error and it seems that the null terminator still exists...
func unmarshalResponse(resp string) ([]interface{}, error) {
var data interface{}
byteRespTrim := []byte(resp)
fmt.Print("found a null terminator at -- ")
fmt.Println(bytes.Index(byteRespTrim, []byte("\x00")))
fmt.Print("total length = ")
fmt.Println(len(byteRespTrim))
byteRespTrim = bytes.Trim(byteRespTrim, "\x00")
fmt.Print("after trim found a null terminator at -- ")
loc := bytes.Index(byteRespTrim, []byte("\x00"))
fmt.Print(loc)
When calling I get the below
(master)⚡ % ./windows-dns-test create -d domain.com -n openshift-node-0 -t A -v 10.90.61.30
found a null terminator at -- 2102
total length = 2615
after trim found a null terminator at -- 2102
From your logs, the offending character seems to be found at position 2102, while the whole array has 2615 elements.
So it looks Trim won't solve it since the problem is not necessarily the final character of the array.
Did you try removing all occurrences, using Replace for example?
byteRespTrim = bytes.Replace(byteRespTrim, []byte("\x00"), []byte{}, -1)

How to replace underscore with dashes when building XML document with Nokogiri?

I'm building a new XML document using the following code:
doc = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do
reginfo {
client_type_id client_type == :associate ? ASSOCIATE : CLIENT
parent_ {
id_ client_type == :associate ? associate_id : customer_id
client_type_id client_type == :associate ? ASSOCIATE : CLIENT
vsn client_type == :associate ? associate_vsn : customer_vsn
}
}
end
The tags above listed as client_type_id show up in the XML file like client_type_id, but that is not the correct XML tag name format. I need them to be client-type-id.
I tried replacing the line with:
:"client-type-id" client_type == :associate ? ASSOCIATE : CLIENT
but I get:
syntax error, unexpected tIDENTIFIER, expecting '}'
:"client-type-id" client_type == :associate ? ASSOCIATE : CLIENT
^
or:
:"client-type-id" (client_type == :associate ? ASSOCIATE : CLIENT)
but I get:
syntax error, unexpected '(', expecting '}'
:"client-type-id" (client_type == :associate ? ASSOCIATE : CLIENT)
^
Is there a way to tell Nokogiri::XML::Builder:
on a per-line basis, to use dashes for a tag name and does it have a different syntax?
that for the entire document, during creation or after, to use dashes for all underscores in element names so that it forms correctly formatted XML element names?
There is a fancy way of doing this:
Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
...
xml.send :"client-type-id", (client_type == :associate ? ASSOCIATE : CLIENT)
...
end

Complex Mule XPath Expression throwing exception

I am trying to run below XPath expressions in Mule. Its giving me errors one after another.
Can someone help me correcting these Mule XPath expressions :
<xm:namespace-manager includeConfigNamespaces="true">
<xm:namespace prefix="acord" uri="ACORD.org/Standards/Life/2" />
<xm:namespace prefix="soap" uri="schemas.xmlsoap.org/soap/envelope/" />
</xm:namespace-manager>
<set-variable variableName="pwaHolding"
value="#[xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/#tc = '37']/#OriginatingObjectID').value" />
<set-variable variableName="pwaPolNumber"
value="#[xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Holding[#id=$pwaHolding]/acord:Policy/acord:PolNumber').text]" />
I am getting below exception when trying to execute above XPATH expressions :
Message :Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/#tc == '37']/#OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. [Error: unexpected token: 37]
[Near : {... #tc == '37']/#OriginatingObjec ....}]
^
[Line: 1, Column: 96] (org.
mvel2.CompileException)
org.mvel2.compiler.ExpressionCompiler:247 (null)
2. Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/#tc == '37']/#OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException)
org.mule.el.mvel.MVELExpressionLanguage:211 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)
3. Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/#tc == '37']/#OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String (org.mule.api.transformer.TransformerMessagingException)
org.mule.transformer.AbstractTransformer:123 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
[Error: unexpected token: 37]
[Near : {... #tc == '37']/#OriginatingObjec ....}] ^
[Line: 1, Column: 96]
at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:247)
at org.mvel2.util.ParseTools.subCompileExpression(ParseTools.java:1944)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:862)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
Hi David,
I even after replacing ' with " I am still getting below error :
Message : Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/#tc == '37']/#OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. [Error: unexpected token: 37]
[Near : {... #tc == '37']/#OriginatingObjec ....}]
^
[Line: 1, Column: 96] (org.mvel2.CompileException)
org.mvel2.compiler.ExpressionCompiler:247 (null)
2. Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/#tc == '37']/#OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException)
org.mule.el.mvel.MVELExpressionLanguage:211 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)
3. Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/#tc == '37']/#OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String (org.mule.api.transformer.TransformerMessagingException)
org.mule.transformer.AbstractTransformer:123 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html)
I have my second XPATH expression in question which is also failing. Please help me get around this as well
The error comes from the fact you use a ' inside a string delimited by ', which can not work. For example in the following expression the issue is around '37':
value="#[xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/#tc = '37']/#OriginatingObjectID').value" />
Another issue is that a closing ] is missing at the end of the MEL expression.
Try with:
value="#[xpath("//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/#tc = '37']/#OriginatingObjectID").value" />
Looking at your second XPath, I see [#id=$pwaHolding]. I assume that at this point you are trying to use the pwaHolding flow variable extracted by the first XPath. This will not work as MVEL does not have string interpolation. You need to instead use concatenation and, by the way, not forget to single quote the value #id is compared to:
[#id‌='" + pwaHolding + "']

Resources