@@ -174,23 +174,11 @@ public ChakraCoreJsEngine(ChakraCoreSettings settings)
174
174
}
175
175
catch ( DllNotFoundException e )
176
176
{
177
- throw WrapTypeLoadException ( e ) ;
178
- }
179
- #if NETSTANDARD1_3
180
- catch ( TypeLoadException e )
181
- #else
182
- catch ( EntryPointNotFoundException e )
183
- #endif
184
- {
185
- throw WrapTypeLoadException( e ) ;
186
- }
187
- catch ( OriginalException e )
188
- {
189
- throw WrapJsException ( e ) ;
177
+ throw WrapDllNotFoundException ( e ) ;
190
178
}
191
179
catch ( Exception e )
192
180
{
193
- throw CoreErrorHelpers . WrapUnknownEngineLoadException ( e , EngineName , EngineVersion ) ;
181
+ throw CoreErrorHelpers . WrapEngineLoadException ( e , EngineName , EngineVersion , true ) ;
194
182
}
195
183
finally
196
184
{
@@ -236,10 +224,7 @@ private static void Initialize()
236
224
}
237
225
catch ( InvalidOperationException e )
238
226
{
239
- string message = string . Format ( CoreStrings . Engine_JsEngineNotLoaded , EngineName ) + " " +
240
- e . Message ;
241
-
242
- throw new WrapperEngineLoadException ( message , EngineName , EngineVersion , e ) ;
227
+ throw CoreErrorHelpers . WrapEngineLoadException ( e , EngineName , EngineVersion ) ;
243
228
}
244
229
}
245
230
@@ -1051,12 +1036,12 @@ private static WrapperException WrapJsException(OriginalException originalExcept
1051
1036
callStackWithSourceFragment = CoreErrorHelpers . StringifyErrorLocationItems ( callStackItems ) ;
1052
1037
}
1053
1038
1054
- message = CoreErrorHelpers . GenerateErrorMessage ( type , description ,
1039
+ message = CoreErrorHelpers . GenerateScriptErrorMessage ( type , description ,
1055
1040
callStackWithSourceFragment ) ;
1056
1041
}
1057
1042
else
1058
1043
{
1059
- message = CoreErrorHelpers . GenerateErrorMessage ( type , description , documentName ,
1044
+ message = CoreErrorHelpers . GenerateScriptErrorMessage ( type , description , documentName ,
1060
1045
lineNumber , columnNumber , sourceFragment ) ;
1061
1046
}
1062
1047
}
@@ -1129,89 +1114,83 @@ private static WrapperException WrapJsException(OriginalException originalExcept
1129
1114
return wrapperException ;
1130
1115
}
1131
1116
1132
- private static WrapperEngineLoadException WrapTypeLoadException (
1133
- TypeLoadException originalTypeLoadException )
1117
+ private static WrapperEngineLoadException WrapDllNotFoundException (
1118
+ DllNotFoundException originalDllNotFoundException )
1134
1119
{
1135
- string originalMessage = originalTypeLoadException . Message ;
1136
- string jsEngineNotLoadedPart = string . Format ( CoreStrings . Engine_JsEngineNotLoaded , EngineName ) ;
1120
+ string originalMessage = originalDllNotFoundException . Message ;
1121
+ string description ;
1137
1122
string message ;
1138
1123
bool isMonoRuntime = Utils . IsMonoRuntime ( ) ;
1139
1124
1140
- if ( originalTypeLoadException is DllNotFoundException
1141
- && ( ( isMonoRuntime && originalMessage == DllName . Universal )
1142
- || originalMessage . ContainsQuotedValue ( DllName . Universal ) ) )
1125
+ if ( ( isMonoRuntime && originalMessage == DllName . Universal )
1126
+ || originalMessage . ContainsQuotedValue ( DllName . Universal ) )
1143
1127
{
1144
1128
const string buildInstructionsUrl =
1145
1129
"https://github.com/Microsoft/ChakraCore/wiki/Building-ChakraCore#{0}" ;
1146
- const string monoInstallationInstructionsUrl =
1130
+ const string manualInstallationInstructionsUrl =
1147
1131
"https://github.com/Taritsyn/JavaScriptEngineSwitcher/wiki/JS-Engine-Switcher:-ChakraCore#{0}" ;
1148
1132
Architecture osArchitecture = RuntimeInformation . OSArchitecture ;
1149
1133
1150
- StringBuilder messageBuilder = StringBuilderPool . GetBuilder ( ) ;
1151
- messageBuilder . Append ( jsEngineNotLoadedPart ) ;
1152
- messageBuilder . Append ( " " ) ;
1153
-
1134
+ StringBuilder descriptionBuilder = StringBuilderPool . GetBuilder ( ) ;
1154
1135
if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
1155
1136
{
1156
- messageBuilder . AppendFormat ( CoreStrings . Engine_AssemblyNotFound , DllName . ForWindows ) ;
1157
- messageBuilder . Append ( " " ) ;
1158
-
1137
+ descriptionBuilder . AppendFormat ( CoreStrings . Engine_AssemblyNotFound , DllName . ForWindows ) ;
1138
+ descriptionBuilder . Append ( " " ) ;
1159
1139
if ( osArchitecture == Architecture . X64 || osArchitecture == Architecture . X86 )
1160
1140
{
1161
- messageBuilder . AppendFormat ( CoreStrings . Engine_NuGetPackageInstallationRequired ,
1141
+ descriptionBuilder . AppendFormat ( CoreStrings . Engine_NuGetPackageInstallationRequired ,
1162
1142
Utils . Is64BitProcess ( ) ?
1163
1143
"JavaScriptEngineSwitcher.ChakraCore.Native.win-x64"
1164
1144
:
1165
1145
"JavaScriptEngineSwitcher.ChakraCore.Native.win-x86"
1166
1146
) ;
1167
- messageBuilder . Append ( " " ) ;
1168
- messageBuilder . Append ( Strings . Engine_VcRedist2015InstallationRequired ) ;
1147
+ descriptionBuilder . Append ( " " ) ;
1148
+ descriptionBuilder . Append ( Strings . Engine_VcRedist2015InstallationRequired ) ;
1169
1149
}
1170
1150
else if ( osArchitecture == Architecture . Arm )
1171
1151
{
1172
- messageBuilder . AppendFormat ( CoreStrings . Engine_NuGetPackageInstallationRequired ,
1152
+ descriptionBuilder . AppendFormat ( CoreStrings . Engine_NuGetPackageInstallationRequired ,
1173
1153
"JavaScriptEngineSwitcher.ChakraCore.Native.win8-arm" ) ;
1174
1154
}
1175
1155
else
1176
1156
{
1177
- messageBuilder . AppendFormat ( CoreStrings . Engine_NoNuGetPackageForProcessorArchitecture ,
1157
+ descriptionBuilder . AppendFormat ( CoreStrings . Engine_NoNuGetPackageForProcessorArchitecture ,
1178
1158
"JavaScriptEngineSwitcher.ChakraCore.Native.win*" ,
1179
1159
osArchitecture . ToString ( ) . ToLowerInvariant ( )
1180
1160
) ;
1181
- messageBuilder . Append ( " " ) ;
1182
- messageBuilder . AppendFormat ( Strings . Engine_BuildNativeAssemblyForCurrentProcessorArchitecture ,
1161
+ descriptionBuilder . Append ( " " ) ;
1162
+ descriptionBuilder . AppendFormat ( Strings . Engine_BuildNativeAssemblyForCurrentProcessorArchitecture ,
1183
1163
DllName . ForWindows ,
1184
1164
string . Format ( buildInstructionsUrl , "windows" )
1185
1165
) ;
1186
1166
}
1187
1167
}
1188
1168
else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
1189
1169
{
1190
- messageBuilder . AppendFormat ( CoreStrings . Engine_AssemblyNotFound , DllName . ForLinux ) ;
1191
- messageBuilder . Append ( " " ) ;
1192
-
1170
+ descriptionBuilder . AppendFormat ( CoreStrings . Engine_AssemblyNotFound , DllName . ForLinux ) ;
1171
+ descriptionBuilder . Append ( " " ) ;
1193
1172
if ( isMonoRuntime )
1194
1173
{
1195
- messageBuilder . AppendFormat ( Strings . Engine_ManualInstallationUnderMonoRequired ,
1174
+ descriptionBuilder . AppendFormat ( Strings . Engine_ManualInstallationUnderMonoRequired ,
1196
1175
"JavaScriptEngineSwitcher.ChakraCore.Native.linux-*" ,
1197
- string . Format ( monoInstallationInstructionsUrl , "linux" )
1176
+ string . Format ( manualInstallationInstructionsUrl , "linux" )
1198
1177
) ;
1199
1178
}
1200
1179
else
1201
1180
{
1202
1181
if ( osArchitecture == Architecture . X64 )
1203
1182
{
1204
- messageBuilder . AppendFormat ( CoreStrings . Engine_NuGetPackageInstallationRequired ,
1183
+ descriptionBuilder . AppendFormat ( CoreStrings . Engine_NuGetPackageInstallationRequired ,
1205
1184
"JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64" ) ;
1206
1185
}
1207
1186
else
1208
1187
{
1209
- messageBuilder . AppendFormat ( CoreStrings . Engine_NoNuGetPackageForProcessorArchitecture ,
1188
+ descriptionBuilder . AppendFormat ( CoreStrings . Engine_NoNuGetPackageForProcessorArchitecture ,
1210
1189
"JavaScriptEngineSwitcher.ChakraCore.Native.linux-*" ,
1211
1190
osArchitecture . ToString ( ) . ToLowerInvariant ( )
1212
1191
) ;
1213
- messageBuilder . Append ( " " ) ;
1214
- messageBuilder . AppendFormat ( Strings . Engine_BuildNativeAssemblyForCurrentProcessorArchitecture ,
1192
+ descriptionBuilder . Append ( " " ) ;
1193
+ descriptionBuilder . AppendFormat ( Strings . Engine_BuildNativeAssemblyForCurrentProcessorArchitecture ,
1215
1194
DllName . ForLinux ,
1216
1195
string . Format ( buildInstructionsUrl , "linux" )
1217
1196
) ;
@@ -1220,31 +1199,30 @@ private static WrapperEngineLoadException WrapTypeLoadException(
1220
1199
}
1221
1200
else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
1222
1201
{
1223
- messageBuilder . AppendFormat ( CoreStrings . Engine_AssemblyNotFound , DllName . ForOsx ) ;
1224
- messageBuilder . Append ( " " ) ;
1225
-
1202
+ descriptionBuilder . AppendFormat ( CoreStrings . Engine_AssemblyNotFound , DllName . ForOsx ) ;
1203
+ descriptionBuilder . Append ( " " ) ;
1226
1204
if ( isMonoRuntime )
1227
1205
{
1228
- messageBuilder . AppendFormat ( Strings . Engine_ManualInstallationUnderMonoRequired ,
1206
+ descriptionBuilder . AppendFormat ( Strings . Engine_ManualInstallationUnderMonoRequired ,
1229
1207
"JavaScriptEngineSwitcher.ChakraCore.Native.osx-*" ,
1230
- string . Format ( monoInstallationInstructionsUrl , "os-x" )
1208
+ string . Format ( manualInstallationInstructionsUrl , "os-x" )
1231
1209
) ;
1232
1210
}
1233
1211
else
1234
1212
{
1235
1213
if ( osArchitecture == Architecture . X64 )
1236
1214
{
1237
- messageBuilder . AppendFormat ( CoreStrings . Engine_NuGetPackageInstallationRequired ,
1215
+ descriptionBuilder . AppendFormat ( CoreStrings . Engine_NuGetPackageInstallationRequired ,
1238
1216
"JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64" ) ;
1239
1217
}
1240
1218
else
1241
1219
{
1242
- messageBuilder . AppendFormat ( CoreStrings . Engine_NoNuGetPackageForProcessorArchitecture ,
1220
+ descriptionBuilder . AppendFormat ( CoreStrings . Engine_NoNuGetPackageForProcessorArchitecture ,
1243
1221
"JavaScriptEngineSwitcher.ChakraCore.Native.osx-*" ,
1244
1222
osArchitecture . ToString ( ) . ToLowerInvariant ( )
1245
1223
) ;
1246
- messageBuilder . Append ( " " ) ;
1247
- messageBuilder . AppendFormat ( Strings . Engine_BuildNativeAssemblyForCurrentProcessorArchitecture ,
1224
+ descriptionBuilder . Append ( " " ) ;
1225
+ descriptionBuilder . AppendFormat ( Strings . Engine_BuildNativeAssemblyForCurrentProcessorArchitecture ,
1248
1226
DllName . ForOsx ,
1249
1227
string . Format ( buildInstructionsUrl , "os-x" )
1250
1228
) ;
@@ -1253,19 +1231,27 @@ private static WrapperEngineLoadException WrapTypeLoadException(
1253
1231
}
1254
1232
else
1255
1233
{
1256
- messageBuilder . Append ( CoreStrings . Engine_OperatingSystemNotSupported ) ;
1234
+ descriptionBuilder . Append ( CoreStrings . Engine_OperatingSystemNotSupported ) ;
1257
1235
}
1258
1236
1259
- message = messageBuilder . ToString ( ) ;
1260
- StringBuilderPool . ReleaseBuilder ( messageBuilder ) ;
1237
+ description = descriptionBuilder . ToString ( ) ;
1238
+ StringBuilderPool . ReleaseBuilder ( descriptionBuilder ) ;
1239
+
1240
+ message = CoreErrorHelpers . GenerateEngineLoadErrorMessage ( description , EngineName ) ;
1261
1241
}
1262
1242
else
1263
1243
{
1264
- message = jsEngineNotLoadedPart + " " +
1265
- string . Format ( CoreStrings . Common_SeeOriginalErrorMessage , originalMessage ) ;
1244
+ description = originalMessage ;
1245
+ message = CoreErrorHelpers . GenerateEngineLoadErrorMessage ( description , EngineName , true ) ;
1266
1246
}
1267
1247
1268
- return new WrapperEngineLoadException ( message , EngineName , EngineVersion , originalTypeLoadException ) ;
1248
+ var wrapperEngineLoadException = new WrapperEngineLoadException ( message , EngineName , EngineVersion ,
1249
+ originalDllNotFoundException )
1250
+ {
1251
+ Description = description
1252
+ } ;
1253
+
1254
+ return wrapperEngineLoadException ;
1269
1255
}
1270
1256
1271
1257
#endregion
0 commit comments