forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsRuntimeErrorHelpers.cs
More file actions
89 lines (84 loc) · 2.96 KB
/
JsRuntimeErrorHelpers.cs
File metadata and controls
89 lines (84 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
namespace JavaScriptEngineSwitcher.Core.Helpers
{
using System;
using System.Globalization;
using System.Text;
using Resources;
using Utilities;
/// <summary>
/// JavaScript error helpers
/// </summary>
public static class JsRuntimeErrorHelpers
{
/// <summary>
/// Generates a detailed error message
/// </summary>
/// <param name="jsEngineLoadException">JavaScript engine load exception</param>
/// <returns>Detailed error message</returns>
public static string Format(JsEngineLoadException jsEngineLoadException)
{
var errorMessage = new StringBuilder();
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Message,
jsEngineLoadException.Message);
if (!string.IsNullOrWhiteSpace(jsEngineLoadException.EngineName))
{
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_EngineName,
jsEngineLoadException.EngineName);
}
if (!string.IsNullOrWhiteSpace(jsEngineLoadException.EngineVersion))
{
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_EngineVersion,
jsEngineLoadException.EngineVersion);
}
return errorMessage.ToString();
}
/// <summary>
/// Generates a detailed error message
/// </summary>
/// <param name="jsRuntimeException">JavaScript runtime exception</param>
/// <returns>Detailed error message</returns>
public static string Format(JsRuntimeException jsRuntimeException)
{
var errorMessage = new StringBuilder();
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Message,
jsRuntimeException.Message);
if (!string.IsNullOrWhiteSpace(jsRuntimeException.EngineName))
{
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_EngineName,
jsRuntimeException.EngineName);
}
if (!string.IsNullOrWhiteSpace(jsRuntimeException.EngineVersion))
{
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_EngineVersion,
jsRuntimeException.EngineVersion);
}
if (!string.IsNullOrWhiteSpace(jsRuntimeException.ErrorCode))
{
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_ErrorCode,
jsRuntimeException.ErrorCode);
}
if (!string.IsNullOrWhiteSpace(jsRuntimeException.Category))
{
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Category,
jsRuntimeException.Category);
}
if (jsRuntimeException.LineNumber > 0)
{
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_LineNumber,
jsRuntimeException.LineNumber.ToString(CultureInfo.InvariantCulture));
}
if (jsRuntimeException.ColumnNumber > 0)
{
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_ColumnNumber,
jsRuntimeException.ColumnNumber.ToString(CultureInfo.InvariantCulture));
}
if (!string.IsNullOrWhiteSpace(jsRuntimeException.SourceFragment))
{
errorMessage.AppendFormatLine("{1}:{0}{0}{2}", Environment.NewLine,
Strings.ErrorDetails_SourceFragment,
jsRuntimeException.SourceFragment);
}
return errorMessage.ToString();
}
}
}