1212import android .os .RemoteException ;
1313import android .provider .ContactsContract ;
1414import android .support .annotation .NonNull ;
15+ import android .support .annotation .Nullable ;
1516import android .text .TextUtils ;
1617import org .thoughtcrime .securesms .logging .Log ;
1718
5354import java .security .SignatureException ;
5455import java .security .cert .CertificateException ;
5556import java .util .ArrayList ;
57+ import java .util .Arrays ;
5658import java .util .Calendar ;
5759import java .util .Collections ;
5860import java .util .HashSet ;
@@ -402,19 +404,19 @@ private static Optional<Set<String>> executeAndMergeContactDiscoveryRequests(@No
402404 }
403405 } catch (InterruptedException e ) {
404406 Log .w (TAG , "Contact discovery batch was interrupted." , e );
405- accountManager .reportContactDiscoveryServiceUnexpectedError ();
407+ accountManager .reportContactDiscoveryServiceUnexpectedError (buildErrorReason ( e ) );
406408 return Optional .absent ();
407409 } catch (ExecutionException e ) {
408410 if (isAttestationError (e .getCause ())) {
409411 Log .w (TAG , "Failed during attestation." , e );
410- accountManager .reportContactDiscoveryServiceAttestationError ();
412+ accountManager .reportContactDiscoveryServiceAttestationError (buildErrorReason ( e . getCause ()) );
411413 return Optional .absent ();
412414 } else if (e .getCause () instanceof PushNetworkException ) {
413415 Log .w (TAG , "Failed due to poor network." , e );
414416 return Optional .absent ();
415417 } else {
416418 Log .w (TAG , "Failed for an unknown reason." , e );
417- accountManager .reportContactDiscoveryServiceUnexpectedError ();
419+ accountManager .reportContactDiscoveryServiceUnexpectedError (buildErrorReason ( e . getCause ()) );
418420 return Optional .absent ();
419421 }
420422 }
@@ -441,6 +443,29 @@ private static KeyStore getIasKeyStore(@NonNull Context context)
441443 return keyStore ;
442444 }
443445
446+ private static String buildErrorReason (@ Nullable Throwable t ) {
447+ if (t == null ) {
448+ return "null" ;
449+ }
450+
451+ String rawString = android .util .Log .getStackTraceString (t );
452+ List <String > lines = Arrays .asList (rawString .split ("\\ n" ));
453+
454+ String errorString ;
455+
456+ if (lines .size () > 1 ) {
457+ errorString = t .getClass ().getName () + "\n " + Util .join (lines .subList (1 , lines .size ()), "\n " );
458+ } else {
459+ errorString = t .getClass ().getName ();
460+ }
461+
462+ if (errorString .length () > 1000 ) {
463+ return errorString .substring (0 , 1000 );
464+ } else {
465+ return errorString ;
466+ }
467+ }
468+
444469 private static class DirectoryResult {
445470
446471 private final Set <String > numbers ;
0 commit comments