How can I capture / log a fatal error in Swift? - swift

For example, fatal error: unexpectedly found nil while unwrapping an Optional value. Regardless of the cause, can this data be captured? Is this stderr or something else?
Edit: I found a reference at http://swiftdoc.org/func/fatalError/ that says the function (which I'm assuming is indeed what Swift is internally calling) "Unconditionally print a message and stop execution.". So perhaps there's nothing left to do but get ahold of the remote crash report via TestFlight crash reports or actually having the device handy.
I'm able to log all uncaught exceptions via NSSetUncaughtExceptionHandler in main.swift, and we have good logging going on in other parts of our app wherever bad (but possible) errors can occur. I was hoping to also log these fatal errors so that our logs show a more complete picture of crashes occuring on remote testing devices.

Certain errors will go to stderr. Here is a simple example:
$ cat tryit
#! /usr/bin/env swift
println ("foo")
precondition (false, "bar")
$ ./tryit 2> /tmp/error 1> /tmp/noterror
Illegal instruction: 4
$ cat /tmp/noterror
$ cat /tmp/error
precondition failed: bar: file ./tryit, line 4
0 swift 0x000000010f7faa18 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x000000010f7faef4 SignalHandler(int) + 452
...
If you remove the precondition, then the results go to stdout:
$ cat tryit
#! /usr/bin/env swift
println ("foo")
$ ./tryit 2> /tmp/error 1> /tmp/noterror
$ cat /tmp/noterror
foo
$ cat /tmp/error

Related

Unable to build Perl module Net::MAC::Vendor

I am unable to build Net::MAC::Vendor on a Mac w/ High Sierra. I am relatively new to Perl but have built modules in the past. The error appears to be:
Failed fetching [https://services13.ieee.org/RST/standards-ra-web/rest/assignments/download/?registry=MA-L&format=html&text=14-10-9F] HTTP status []
message [IO::Socket::SSL 2.009+ required for TLS support] at t/fetch_oui_from_custom.t line 21.
Could not fetch data from the IEEE! at t/fetch_oui_from_custom.t line 21.
# Failed test ''Got back array reference' isa 'ARRAY''
# at t/fetch_oui_from_custom.t line 23.
# 'Got back array reference' isn't defined
# Failed test 'Fetched Apple's OUI entry'
# at t/fetch_oui_from_custom.t line 25.
# ''
# doesn't match '(?^:Apple, Inc\.)'
# Looks like you failed 2 tests of 2.
t/fetch_oui_from_custom.t .. 2/?
# Failed test 'fetch'
# at t/fetch_oui_from_custom.t line 27.
Use of uninitialized value in concatenation (.) or string at /Users/johnprokopek/.cpan/build/Net-MAC-Vendor-1.265-13/blib/lib/Net/MAC/Vendor.pm line 320.
Failed fetching [http://standards.ieee.org/cgi-bin/ouisearch?14-10-9F] HTTP status []
Can someone help, thanks
I'm also still on High Sierra (10.13.6), on an ancient-but-still-running Mac Mini mid-2010. Using the built-in /usr/bin/perl (v5.18.2), running install Net::MAC::Vendor inside the CPAN shell gave me the same error. Running force install Net::MAC::Vendor worked, in that the module was installed.
A simple perl -MNet::MAC::Vendor -e "print 'hi'" works, so it looks like Perl can at least load that library, not really sure how to test that it works for real. But, at least this will let you install it and try it.

syntax error near unexpected token `(' with quoted arguments with gdbserver

My program accepts quoted arguments which contain brackets inside. If I pass these arguments to a gdbserver as if I run it standalone, I get an error
syntax error near unexpected token `('
Example of standalone run:
myprogram 12 3 "sin(x)"
Example of gdbserver run:
gdbserver :2345 myprogram 12 3 "sin(x)"
How to overcome?
I faced the same problem and this is what helped to me:
gdbserver :2345 myprogram 12 3 "'sin(x)'"

perl module Class::HPLOO v0.23 install issue #2

Having the exact issue as described at: perl module Class::HPLOO v0.23 install issue, I have attempted to correct the defined(#array) problem by editing to just (#array) and trying to rebuild the module. However I continue to get the return of:
$ make clean
$ perl Makefile.PL
$ make
$ make test: *** No rule to
make target `clean:'. Stop. Manifying 2 pod documents
PERL_DL_NONLAZY=1 "/opt/local/bin/perl5.26" "-Iblib/lib" "-Iblib/arch"
test.pl
1..42
# Running under perl version 5.026002 for darwin
# Current time local: Sun Aug 26 06:48:26 2018
# Current time GMT: Sat Aug 25 22:48:26 2018
# Using Test.pm version 1.26 not ok 1
# Failed test 1 in test.pl at line 9
# test.pl line 9 is: ok(!$#) ; Can't locate object method "new" via package "Foo" at test.pl line 11. make: *** [test_dynamic] Error 2
There are three issues with Class::HPLOO (which as I noted before, hasn't been updated since 2005) that make it fail with modern perls.
As discovered in the previous post,
the obsolete construct defined (#array) is used once in lib/Class/HPLOO.pm' and three times inlib/Class/HPLOO/Base.pm`. This construction has been prohibited since v5.22
The current directory (.) is no longer in #INC (as of v5.24, I think). So the lines in test.pl like
require "test/classtest.pm"
either all need to be rewritten as
require "./test/classtest.pm"
or an easier fix is to put
use lib '.';
at the top of the script.
There is a regular expression in lib/Class/HPLOO.pm, line 1077, with an "unescaped left brace"
$sub =~ s/(\S)( {) (\S)/$1$2\n$FIRST_SUB_IDENT $3/gs ;
{ is a regex metacharacter, and since v5.22 it has been illegal to use it in a context where it is not indicating a quantity. The fix, as the error message suggests, is to escape it.
$sub =~ s/(\S)( \{) (\S)/$1$2\n$FIRST_SUB_IDENT $3/gs ;
Make these three changes to the code you download from CPAN and the module should build on modern Perls. If you're feeling helpful, you can submit a bug report (linking to this post, if you want) or even a patch with an email to bug-Class-HPLOO#rt.cpan.org
come across this issue today, so I fixed it following the answer above. if anyone want to save some time.
I create a repo with the changes. https://github.com/swuecho/Class_HPLOO.git

Unexpected EOF when linking Arduino project in Eclipse on OS X

I have been trying to link Arduino and Eclipse, and I feel like I'm close.
Where should I start looking for this?
Similar errors have been caused by extra/incomplete quote blocks (according to google searches). I have already dug through my AVR linker settings looking for quotes, but haven't had much luck.
Am I looking in the right place?
Which files should I check?
I have already looked in the file I have written myself (in this case, the basic Arduino blink program).
**** Build of configuration Release for project C64_Arduino1 ****
make all
Building target: C64_Arduino1.elf
Invoking: AVR C++ Linker
avr-gcc --cref -s -Os -o"C64_Arduino1.elf" ./C64_Arduino1.o ./CDC.o ./HID.o
./HardwareSerial.o ./Print.o ./Stream.o ./Tone.o ./USBCore.o ./WInterrupts.o ./WMath.o ./WString.o ./malloc.o ./wiring.o ./wiring_analog.o ./wiring_digital.o ./wiring_pulse.o
./wiring_shift.o -l"Arduino_Mega_2560_or_Mega_ADK" -lm -L/Users/Chet/Desktop/Chet's Shit/Side Projects/Programming/C64_Arduino1/Release -L"/Users/Chet/Desktop/Chet's Shit/Side
Projects/Programming/C64_Arduino1" -mmcu=atmega2560
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [C64_Arduino1.elf] Error 2
**** Build Finished ****
EDIT:
I have commented out all of my code (including #include's) except the main (which is empty) and I still get the error. I have set up my IDE as specified Here and also Here. Still nothing.
Looking at the actual error message:
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file
I can see that the problem is most likely due to some kind of Makefile syntax error.
When you write a make rule such like:
foo:
touch foo
What make does, it first checkes whether file called foo exists already, if not, then it runs command /bin/sh -c 'touch foo'. So the line where we said touch foo should have valid shell script syntax.
Looking at the command that you ended up running:
avr-gcc --cref -s -Os -o"C64_Arduino1.elf" ./C64_Arduino1.o ./CDC.o ./HID.o
./HardwareSerial.o ./Print.o ./Stream.o ./Tone.o ./USBCore.o ./WInterrupts.o ./WMath.o ./WString.o ./malloc.o ./wiring.o ./wiring_analog.o ./wiring_digital.o ./wiring_pulse.o
./wiring_shift.o -l"Arduino_Mega_2560_or_Mega_ADK" -lm -L/Users/Chet/Desktop/Chet's Shit/Side Projects/Programming/C64_Arduino1/Release -L"/Users/Chet/Desktop/Chet's Shit/Side
Projects/Programming/C64_Arduino1" -mmcu=atmega2560
I can see that the issue is with the ' character in some of the directory paths. You should either escape it (as in "/Users/Chet/Desktop/Chet\'s Shit") or, as a quick work-around symlink or move the directory.
As a general methodology tip, you should first check whether everything works in CLI, and then move on to teaching Eclipse what commands it should run.
Also, I would consider using the tool called ino instead of make, it might just work with minimum configuration. I have had some experience replacing Arduino IDE with just a Makefile, but it gets hairy when you need to use different boards and perhaps several connected at the same time. Give ino a try, it looks quite promising.

Instruments failing to launch from command line

I have been trying to run Instruments from the command line.
But it fails with the following error:
2012-02-08 14:48:16.104 instruments[94502:60f] -[NSAlert alertWithError:] called
with nil NSError. A generic error message will be displayed,
but the user deserves better.
Wed Feb 8 14:48:16 c1dev-dm23409.overstock.com instruments[94502]
<Error>: kCGErrorInvalidConnection: CGSGetCurrentCursorLocation: Invalid connection
Wed Feb 8 14:48:16 c1dev-dm23409.overstock.com instruments[94502]
<Error>: kCGErrorFailure: Set a breakpoint #CGErrorBreakpoint() to catch errors as
they are logged.
2012-02-08 14:48:16.137 instruments[94502:60f] Recording cancelled : At least
one target failed to launch; aborting run
Can some tell me what I am missing?
I believe the errors Invalid connection and the following Set a breakpoint... are what Instruments responds with when it has any kind of problem.
What's really important is the last line: Recording cancelled : At least one target failed to launch.
In my experience, this either means that your program was unable to load (provisioning profile, nonexistent build, etc) or that you didn't specify it correctly on the command line. Here's how I specify instruments:
$ instruments -t /Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate
/path/to/my/AppName.app -e UIARESULTSPATH . -e UIASCRIPT testscript.js