How can I print a line break in a stacktrace? - crashlytics

\n doesn't seem to work.
I should mention this extraordinary case, in which the \n does the trick.
Arrays.toString(e.getStackTrace()).replaceAll(",", "\n")
In fact, if I try to do
catch {
Crashlytics.logException(new IllegalStateException(
Arrays.toString(e.getStackTrace()).replaceAll(",", "\n") + ".\n" +
"b"
));
}
The stacktrace is printed with every entry on one line, BUT b is printed on the same line the stacktrace finishes.
This is just an example with the stacktrace, all the others
Crashlytics.logException(new IllegalStateException(
"a\nb"
));
do not work and do print ab indeed.
Note that this counts even for the "expanded" stacktrace, in other words, when you click on the </>raw button and the stacktrace expands, the two letters are still on the same line.
How can I print a line break in Crashlytics?

Related

Else syntax error when nesting array formula

I am recieving a syntax error on "else" for this shell:
{for (i=8;i<=NF;i+=3)
{if ($0~"=>") # if-else statement designed to flag file / directory transfers
print "=> flag,"$1"," $2","$3","$4 ","$5","$6","$7"," $(i)","$(i+1)","$(i+2);
{split ($(i+2), array, "/");
for (x in array)
{j++;
a[j] =j;
printf (array[x] ",");}
printf ("%s\n", "");}
else
print "no => flag,"$1"," $2","$3","$4 ","$5","$6","$7"," $(i)","$(i+1)","$(i+2)
}
}
Can't figure out why. If I delete the array block (starting with split()), all is well. But I need to scan the contents of $(i+2), so cutting it does me no good.
Also, if anyone has guidance on a good list of how to interpret error messages, that would be great.
Thanks for your advice.
EDIT: here is the above script laid out with sensible formatting:
{
for (i=8;i<=NF;i+=3) {
if ($0~"=>") # if-else statement designed to flag file / directory transfers
print "=> flag,"$1"," $2","$3","$4 ","$5","$6","$7"," $(i)","$(i+1)","$(i+2);
{
split ($(i+2), array, "/");
for (x in array) {
j++;
a[j] =j;
printf (array[x] ",");
}
printf ("%s\n", "");
}
else
print "no => flag,"$1"," $2","$3","$4 ","$5","$6","$7"," $(i)","$(i+1)","$(i+2)
}
}
First thing first, since you didn't post any samples of input and expected output so didn't test it at all. Could you please try following, I hope you are running this in .awk script style. Also these are mostly syntax/cosmetic changes NOT on logic part, since no background was given on problem.
BEGIN{
OFS=","
}
{
for (i=8;i<=NF;i+=3){
if ($0~/=>/){
print "=> flag,"$1,$2,$3,$4,$5,$6,$7,$(i),$(i+1),$(i+2)
split ($(i+2), array, "/");
for(x in array){
j++;
a[j] =j;
printf (array[x] ",")
}
printf ("%s\n", "")
}
else{
print "no => flag",$1,$2,$3,$4,$5,$6,$7,$(i),$(i+1),$(i+2)
}
}
}
Problems fixed in OP's attempt:
{ starting curly braces(which indicates that if condition of for loop with multiple statements is started) could be in last of the line where they are present, NOT in next line, for better visibility purposes, I fixed in for loop and if condition first.
Since you are using regexp matching with a pattern so I fixed from $0~"=>" TO $0~/=>/.
Added BEGIN section in your attempt where I have set OFS(output field separator) value to , so that you need NOT to print like "," to print comma between variables, just , between variables will do the trick.
Fixed indentation, so that we are NOT confused where to close loop/condition and where to NOT.

Endless recursion in gawk-script

Please pardon me in advance for posting such a big part of my problem, but I just can't put my finger on the part that fails...
I got input-files like this (abas-FO if you care to know):
.fo U|xiininputfile = whatever
.type text U|xigibsgarnich
.assign U|xigibsgarnich
..
..Comment
.copy U|xigibswohl = Spaß
.ein "ow1/UWEDEFTEST.FOP"
.in "ow1/UWEINPUT2"
.continue BOTTOM
.read "SOemthing" U|xttmp
!BOTTOM
..
..
Now I want to recursivly follow each .in[put]/.ein[gabe]-statement, parse the mentioned file and if I don't know it yet, add it to an array. My code looks like this:
#!/bin/awk -f
function getFopMap(inputregex, infile, mandantdir, infiles){
while(getline f < infile){
#printf "*"
#don't match if there is a '
if(f ~ inputregex "[^']"){
#remove .input-part
sub(inputregex, "", f)
#trim right
sub(/[[:blank:]]+$/, "", f)
#remove leading and trailing "
gsub(/(^\"|\"$)/,"" ,f)
if(!(f in infiles)){
infiles[f] = "found"
}
}
}
close(infile)
for (i in infiles){
if(infiles[i] == "found"){
infiles[i] = "parsed"
cmd = "test -f \"" i "\""
if(system(cmd) == 0){
close(cmd)
getFopMap(inputregex, f, mandantdir, infiles)
}
}
}
}
BEGIN{
#Matches something like [.input myfile] or [.ein "ow1/myfile"]
inputregex = "^\\.(in|ein)[^[:blank:]]*[[:blank:]]+"
#Get absolute path of infile
cmd = "python -c 'import os;print os.path.abspath(\"" ARGV[1] "\")'"
cmd | getline rootfile
close(cmd)
infiles[rootfile] = "parsed"
getFopMap(inputregex, rootfile, mandantdir, infiles)
#output result
for(infile in infiles) print infile
exit
}
I call the script (in the same directory the paths are relative to) like this:
./script ow1/UWEDEFTEST.FOP
I get no output. It just hangs up. If I remove the comment before the printf "*" command, I'm seeing stars, without end.
I appreciate every help and hints how to do it better.
My awk:
gawk Version 3.1.7
idk it it's your only problem but you're calling getline incorrectly and consequently will go into an infinite loop in some scenarios. Make sure you fully understand all of the caveats at http://awk.info/?tip/getline and you might want to use the recursion example there as the starting point for your code.
The most important item initially for your code is that when getline fails it can return a negative value so then while(getline f < infile) will create an infinite loop since the failing getline will always be returning non-zero and will so continue to be called and continue to fail. You need to use while ( (getline f < infile) > 0) instead.

Use of uninitialized value in concatenation (.) or string at

I've this error:
Use of uninitialized value in concatenation (.) or string at...
This is my code:
$queryH= $dbh->prepare($query);
$queryH->execute();
my $i=0;
my $result;
while (#data = $queryH->fetchrow_array())
{
$result=$data[$i];
if ($result)
{
print "$result \n";
}
else
{
print "Records Not Found!\n";
last;
}
print "\n";
$i++;
}
print "\n\n";
$queryH->finish();
$dbh->disconnect();
What error is there in my code?
The error is on the line:
$result=$data[$i];
You are starting out with $i=0 and you increment it with each pass of the while loop. You look at $data[$i] once for each line of database result. So for the first row, you look at $data[0]. For the second row of data, you look at $data[1] and so on. At some point, your $i (which is effectively a rowcount starting at zero) will be higher than the number of fields per row. That produces the error message.
If you put in a print "$i\n" in the beginning of the while block you will see what I am talking about.

Awk iterating with out a loop construct

I was reading a tutorial on awk scripting, and observed this strange behaviour, Why this awk script while executing asks for a number repeatedly even with out a loop construct like while or for. If we enter CTRL+D(EOF) it stops prompting for another number.
#!/bin/awk -f
BEGIN {
print "type a number";
}
{
print "The square of ", $1, " is ", $1*$1;
print "type another number";
}
END {
print "Done"
}
Please explain this behaviour of the above awk script
awk continues to work on lines until end of file is reached. Since in this case the input (STDIN) never ends as you keep entering number or hitting enter, it causes an endless loop.
When you hit CTRL+D you indicate the awk script that EOF is reached there by exiting the loop.
try this and enter 0 to exit
BEGIN {
print "type a number";
}
{
if($1==0)
exit;
print "The square of ", $1, " is ", $1*$1;
print "type another number";
}
END {
print "Done"
}
From the famous The AWK Programming Language:
If you don't provide a input file to the awk script on the command line, awk will apply the program to whatever you type next on your terminal until you type an end-of-file signal (control-d on Unix systems).

Getting output for every line of input file. Only need output once

This should be pretty simple but I'm having an issue with the flow of an awk script. I run the following script and it prints the output over and over again (if I had to guess I would say that it's printing once for every line of the input file). As requested, here is some fake input:
[30000] (03/20 00:00:02.950):{0x2D90} Pattern1 5.0.3.57
[30000] (03/20 00:00:03.911):{0x2D90} Pattern2 5.0.3.57
[30000] (03/20 00:00:02.950):{0x2D90} Pattern3 5.0.3.16
[30000] (03/20 00:00:03.911):{0x2D90} Pattern4 5.0.3.16
Here is the script:
/Pattern1/ {
gsub(/\./,"");
agtver=$5;
}
/Pattern2/ {
gsub(/\./,"");
ctrver=$5;
}
{
if (agtver ~ 50357 && ctrver ~ 50357) {
print "Blamo!";
}
else print "No blamo. :("
}
And here is the output that I'm getting:
[chawkins#chawkins-DT Devel]$ ./fakeawk.awk < fake.txt
No blamo. :(
Blamo!
Blamo!
Blamo!
The output that I expect is a single Blamo! if the patterns match and a single No blamo. :( if it doens't match.
The problem seems to be that there are three separate { ... } sections, but I need these to be able to process two patterns... unless there is a way to condense this.
If you never see pattern1 and pattern2 after the first time, then agtver and ctrver remain set. You have to zero them out again.
edit added debug output, you should be able to see where the logic is failing.
Tested with your data, thanks for adding that!
/Pattern1/ { gsub(/\./,""); agtver=$5;}
/Pattern2/ { gsub(/\./,""); ctrver=$5;}
{
#dbg print "\n#dbg: $5=" $5 "xx\tagtver=" agtver "xx\tctrver=" ctrver "xxx\t$0=" $0
if (agtver ~ 50357 && ctrver ~ 50357) {
print "Blamo!";
agtver="" ; ctrver=""
}
else print "No blamo. :("
}
./fakeawk.awk < fake.txt
output
No blamo. :(
Blamo!
No blamo. :(
No blamo. :(
I hope this helps.
TXR:
#(gather :vars (agtver ctrver))
# (skip :greedy) #/Pattern1/ #{agtver /5\.0\.3\.57/}
# (skip :greedy) #/Pattern2/ #{ctrver /5\.0\.3\.57/}
#(end)
#(do (put-string "Blamo!\n"))
Output:
$ txr fake.txr fake.log
Blamo!
$ echo "junk" | txr fake.txr -
false
The #(gather) directive is perfect for this. It matches material that can appear in any order, and :vars (agtver ctrver) adds the constraint that bindings must be found for both of these variables, or else a failure occurs.
We can then express the two indepedent conditions we are looking for as a pair of independent whole-line pattern matches which bind two different variables.
The logic may be read as "please scan the input to gather bindings variables agtver and ctrver or else fail". And then the rules for gathering the variables are specified, one per line.
We don't really need the side effect of printing Blamo!: the successful or failed termination of the program tells us everything.