3
3
4
4
using System ;
5
5
using System . Configuration ;
6
+ using System . Text ;
6
7
7
8
namespace Microsoft . Azure . WebJobs . Script
8
9
{
9
- internal static class Utility
10
+ public static class Utility
10
11
{
11
12
public static string GetFunctionShortName ( string functionName )
12
13
{
@@ -21,14 +22,47 @@ public static string GetFunctionShortName(string functionName)
21
22
22
23
public static string FlattenException ( Exception ex )
23
24
{
24
- string formattedError = ex . Message ;
25
+ StringBuilder flattenedErrorsBuilder = new StringBuilder ( ) ;
26
+ string lastError = null ;
25
27
26
- while ( ( ex = ex . InnerException ) != null )
28
+ if ( ex is AggregateException )
27
29
{
28
- formattedError += ". " + ex . Message ;
30
+ ex = ex . InnerException ;
29
31
}
30
32
31
- return formattedError ;
33
+ do
34
+ {
35
+ StringBuilder currentErrorBuilder = new StringBuilder ( ) ;
36
+ if ( ! string . IsNullOrEmpty ( ex . Source ) )
37
+ {
38
+ currentErrorBuilder . AppendFormat ( "{0}: " , ex . Source ) ;
39
+ }
40
+
41
+ currentErrorBuilder . Append ( ex . Message ) ;
42
+
43
+ if ( ! ex . Message . EndsWith ( "." ) )
44
+ {
45
+ currentErrorBuilder . Append ( "." ) ;
46
+ }
47
+
48
+ // sometimes inner exceptions are exactly the same
49
+ // so first check before duplicating
50
+ string currentError = currentErrorBuilder . ToString ( ) ;
51
+ if ( lastError == null ||
52
+ string . Compare ( lastError . Trim ( ) , currentError . Trim ( ) ) != 0 )
53
+ {
54
+ if ( flattenedErrorsBuilder . Length > 0 )
55
+ {
56
+ flattenedErrorsBuilder . Append ( " " ) ;
57
+ }
58
+ flattenedErrorsBuilder . Append ( currentError ) ;
59
+ }
60
+
61
+ lastError = currentError ;
62
+ }
63
+ while ( ( ex = ex . InnerException ) != null ) ;
64
+
65
+ return flattenedErrorsBuilder . ToString ( ) ;
32
66
}
33
67
34
68
public static string GetAppSettingOrEnvironmentValue ( string name )
0 commit comments