Jacoco branch missed after try-with-resources with no catch - code-coverage

I have a try-with-resources with no catch or finally. I am able to get 100% line coverage but I am unable to cover 1 branch at line 249. The branch is code from try-with-resources.
Notice that line 251 is covered (i.e., return true). Notice that line 247 is covered and this throws an exception.
I wrote a test case that causes Files.newInputStream() to throw an IOException. This did not cover the missing branch.
What test case am I missing?

Move the contents of the try block to another method.
I wonder if the return false in the try block is causing the problem.

Related

How to get more information for an error generated in libcontainer/rootfs_linux.go?

Code used from github: https://github.com/opencontainers/runc/blob/master/libcontainer/rootfs_linux.go#L59
This is the if block to debug for our interest....
if err := mountToRootfs(m, config.Rootfs, config.MountLabel, hasCgroupns); err != nil {
return newSystemErrorWithCausef(err, "mounting %q to rootfs at %q", m.Source, m.Destination)
}
Here in the if condition, there is an error generated thru newSystemErrorWithCausef function and which internally uses generic_error.go, fmt.Sprintf to format the error string.
In our integration, only once it hit this if block. And in the process of getting more details, I wanted to troubleshoot and understand why this happened.
As of now tried using fmt.Printf(........) in line 55 and also just before if block of line 59.
And also tried putting above statement in very first line of prepareRootfs function. And then tried newSystemErrorWithCause(err, "some other message") in the first line of prepareRootfs function. Overall I dont see any information generated with my messages.
Please provide any information to understand more of this issue. Please note I am not looking for why this error might have been caused. I am looking for how to get more information from that function of prepareRootfs.

How to identify exactly where exception occurred in Jenkins pipeline?

In Jenkins pipeline build, sometimes I've seen null pointer or other exceptions like -
java.lang.NullPointerException: Cannot invoke method trim() on null object
Generally if we run Java program through IDE or command line, if an exception occurs we see at which line number the exception has occurred.
But with Jenkins build output console, it does not show the line number where the exception has occurred.
In this case, based on method name ie trim() from log, I check wherever trim() method is used. But as I've used it at multiple places in same method, it becomes difficult to identify exactly where error has occurred.
Another way is to add echo statements and re-run build and see where it gives this exception but this is time consuming.
Is there any better way/plugin using which I can identify at which line of pipeline code exception has occurred?
I don't really know if it's possible to show the exact line number, but you can wrap your code in try-catch statements and then show the exception info in the catch, like so:
try {
// line with trim()
catch (ex) {
println "Exception while trimming: $ex"
}

What does this ejabberd / erlang stack trace mean?

could someone help me figure out what to look for in this stacktrace? I've never touched Erlang, so I don't really know where to start.
We're using v19.09 of ejabberd, and getting this error log for many users:
2020-03-14 15:29:31.096 [error] <0.2029.48>#mod_http_api:handle:257 REST API Error: set_presence([{<<"user">>,<<"53265363">>},{<<"host">>,<<"chat.us.com">>},{<<"resource">>,<<"ssid-3465">>},{<<"type">>,<<"available">>},{<<"show">>,<<"chat">>},{<<"status">>,<<"{\"current_lobby_id\":\"none\",\"status\":\"{\\r\
\\t\\\"rich_presence\\\": \\\"{\\\\r\\\
\\\\t\\\\\\\"rich_presence\\\\\\\": \\\\\\\"?s=PlayerStatusInMap?p0=21?p1=2?p2=3\\\\\\\",\\\\r\\\
\\\\t\\\\\\\"session_id\\\\\\\": \\\\\\\"ssid-3465-38a44f60-9df7-4c79-8c8e-1cc99e5039dd\\\\\\\"\\\\r\\\
}\\\",\\r\
\\t\\\"current_lobby_id\\\": \\\"{\\\\r\\\
\\\\t\\\\\\\"lobby_id\\\\\\\": \\\\\\\"c791cfaa-9fd3-4d0d-9d5c-1aeb9efb12e2#hangouts.chat.us.com\\\\\\\",\\\\r\\\
\\\\t\\\\\\\"privacy\\\\\\\": \\\\\\\"friends_only\\\\\\\"\\\\r\\\
}\\\"\\r\
}\",\"region\":\"\"}">>},{<<"priority">>,<<"0">>}]) -> exit:{noproc,{p1_server,call,[none,{set_presence,{presence,<<>>,available,<<>>,{jid,<<"953265363">>,<<"chat.us.com">>,<<"oak/ssid-3465-1cc99e5039dd">>,<<"1953265363">>,<<"chat.us.com">>,<<"4c79-8c8e-1cc99e5039dd">>},{jid,<<"1953265363">>,<<"chat.us.com">>,<<>>,<<"1953265363">>,<<"chat.us.com">>,<<>>},chat,[{text,<<"en">>,<<"{\"current_lobby_id\":\"none\",\"status\":\"{\\r\
\\t\\\"rich_presence\\\": \\\"{\\\\r\\\
\\\\t\\\\\\\"rich_presence\\\\\\\": \\\\\\\"?s=PlayerStatusInMap?p0=21?p1=2?p2=3\\\\\\\",\\\\r\\\
\\\\t\\\\\\\"session_id\\\\\\\": \\\\\\\"ssid-348c8e-1cc99e5039dd\\\\\\\"\\\\r\\\
}\\\",\\r\
\\t\\\"current_lobby_id\\\": \\\"{\\\\r\\\
\\\\t\\\\\\\"lobby_id\\\\\\\": \\\\\\\"c791cfaa-9fd3-4d0d-9d5c-1aeb9efb12e2#hangouts.chat.us.com\\\\\\\",\\\\r\\\
\\\\t\\\\\\\"privacy\\\\\\\": \\\\\\\"friends_only\\\\\\\"\\\\r\\\
}\\\"\\r\
}\",\"region\":\"\"}">>}],0,[],#{}}},1000]}} [{p1_server,call,3,[{file,"src/p1_server.erl"},{line,210}]},{mod_http_api,handle2,4,[{file,"src/mod_http_api.erl"},{line,267}]},{mod_http_api,handle,4,[{file,"src/mod_http_api.erl"},{line,228}]},{mod_http_api,perform_call,4,[{file,"src/mod_http_api.erl"},{line,188}]},{mod_http_api,process,2,[{file,"src/mod_http_api.erl"},{line,141}]},{ejabberd_http,process,2,[{file,"src/ejabberd_http.erl"},{line,366}]},{ejabberd_http,process_request,1,[{file,"src/ejabberd_http.erl"},{line,488}]},{ejabberd_http,process_header,2,[{file,"src/ejabberd_http.erl"},{line,286}]}]
Start with the actual error, which is buried in the middle:
exit:{noproc,{p1_server,call,[none,{set_presence,.....
So there is a noproc error, which occurred during a call to p1_server:call, where the first argument is none. (The call would look like p1_server:call(none, {set_presence,...}).) That is, we're asking the process called none to execute the command set_presence, which fails because there is no process registered with the name none.
Now let's look at the stack trace. I added line breaks:
[{p1_server,call,3,[{file,"src/p1_server.erl"},{line,210}]},
{mod_http_api,handle2,4,[{file,"src/mod_http_api.erl"},{line,267}]},
{mod_http_api,handle,4,[{file,"src/mod_http_api.erl"},{line,228}]},
{mod_http_api,perform_call,4,[{file,"src/mod_http_api.erl"},{line,188}]},
{mod_http_api,process,2,[{file,"src/mod_http_api.erl"},{line,141}]},
{ejabberd_http,process,2,[{file,"src/ejabberd_http.erl"},{line,366}]},
{ejabberd_http,process_request,1,[{file,"src/ejabberd_http.erl"},{line,488}]},
{ejabberd_http,process_header,2,[{file,"src/ejabberd_http.erl"},{line,286}]}]
The first line is where it discovers that there is no such process, on line 210 in p1_server.erl. But we're more interested in why we're passing none as the argument in the first place. The stack trace suggests that's happening somewhere in mod_http_api.erl, but at that point I'm getting lost - it seems like it's extracting the arguments from the command, but I don't understand where the none is coming from...

Error running call reference function

I am having an error whilst trying to run a resource on a game server. I believe this line of code in the console is the issue;
Error running call reference function for resource es_extended:
citizen:/scripting/lua/scheduler.lua:351: server/main.lua:237: attempt to
index a nil value (global 'Async')
I have been to line 351 to find this;
error(err)
I then went to line 237 to find this;
Async.parallel(tasks, function(results)
I cannot see for the life of me anything wrong with either lines of code. So any and all advice is greatly recieved.
The global variable Async is a nil value. Hence indexing it like this:
Async.parallel
is not possible. Therefor Lua throws an error.
To fix it, find out why Async is nil and change that, or do not index it.

How to print a message when an assert fails, in Dart?

We'd like to print a message when an assert() fails. Currently in Dart, an assert only takes a boolean. We'd like to give the developer explicit reasons and instructions for what to do when the assert fails.
As of Dart 1.22, assert() takes an optional message.
assert(configFile != null, "Tool config missing.");
If the assertion fails, it will produce something like the following:
Unhandled exception:
'file:///.../main.dart': Failed assertion: line 9 pos 10:
'configFile != null': Tool config missing.
#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:33)
#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:29)
#2 main (file:///.../main.dart:9:10)
Note that the error message includes the actual assertion (configFile != null).
Just to add, if you're executing a dart file via command line, you need to enable asserts as follows, see reference here:
dart --enable-asserts main.dart
There is an open issue with a workaround https://github.com/dart-lang/sdk/issues/6190#issuecomment-119103626
assert(() => test || throw "message");
I tried this but this way it doesn't work. A slightly modified working version
var test = false;
assert(test ? true : throw "message");
See also
https://groups.google.com/a/dartlang.org/forum/#!topic/core-dev/yNiTFYmtmwY
https://github.com/dart-lang/sdk/issues/24213
https://github.com/sethladd/dep_assert_with_optional_message/blob/master/proposal.md

Resources