@@ -250,29 +250,49 @@ private WrapperException WrapJsException(OriginalException originalException,
250
250
|| errorValueType == JsValueType . Object )
251
251
{
252
252
EdgeJsValue messagePropertyValue = errorValue . GetProperty ( "message" ) ;
253
- description = messagePropertyValue . ConvertToString ( ) . ToString ( ) ;
253
+ string localDescription = messagePropertyValue . ConvertToString ( ) . ToString ( ) ;
254
+ if ( ! string . IsNullOrWhiteSpace ( localDescription ) )
255
+ {
256
+ description = localDescription ;
257
+ }
254
258
255
259
EdgeJsValue namePropertyValue = errorValue . GetProperty ( "name" ) ;
256
260
type = namePropertyValue . ValueType == JsValueType . String ?
257
- namePropertyValue . ConvertToString ( ) . ToString ( ) : string . Empty ;
261
+ namePropertyValue . ToString ( ) : string . Empty ;
258
262
259
- EdgeJsPropertyId stackPropertyId = EdgeJsPropertyId . FromString ( "stack " ) ;
260
- if ( errorValue . HasProperty ( stackPropertyId ) )
263
+ EdgeJsPropertyId descriptionPropertyId = EdgeJsPropertyId . FromString ( "description " ) ;
264
+ if ( errorValue . HasProperty ( descriptionPropertyId ) )
261
265
{
262
- EdgeJsPropertyId descriptionPropertyId = EdgeJsPropertyId . FromString ( "description" ) ;
263
- if ( errorValue . HasProperty ( descriptionPropertyId ) )
266
+ EdgeJsValue descriptionPropertyValue = errorValue . GetProperty ( descriptionPropertyId ) ;
267
+ localDescription = descriptionPropertyValue . ConvertToString ( ) . ToString ( ) ;
268
+ if ( ! string . IsNullOrWhiteSpace ( localDescription ) )
264
269
{
265
- EdgeJsValue descriptionPropertyValue = errorValue . GetProperty ( descriptionPropertyId ) ;
266
- if ( descriptionPropertyValue . ValueType == JsValueType . String
267
- && descriptionPropertyValue . StringLength > 0 )
268
- {
269
- description = descriptionPropertyValue . ConvertToString ( ) . ToString ( ) ;
270
- }
270
+ description = localDescription ;
271
271
}
272
+ }
272
273
274
+ if ( type == JsErrorType . Syntax )
275
+ {
276
+ errorCode = JsErrorCode . ScriptCompile ;
277
+ }
278
+ else
279
+ {
280
+ EdgeJsPropertyId numberPropertyId = EdgeJsPropertyId . FromString ( "number" ) ;
281
+ if ( errorValue . HasProperty ( numberPropertyId ) )
282
+ {
283
+ EdgeJsValue numberPropertyValue = errorValue . GetProperty ( numberPropertyId ) ;
284
+ int errorNumber = numberPropertyValue . ValueType == JsValueType . Number ?
285
+ numberPropertyValue . ToInt32 ( ) : 0 ;
286
+ errorCode = ( JsErrorCode ) errorNumber ;
287
+ }
288
+ }
289
+
290
+ EdgeJsPropertyId stackPropertyId = EdgeJsPropertyId . FromString ( "stack" ) ;
291
+ if ( errorValue . HasProperty ( stackPropertyId ) )
292
+ {
273
293
EdgeJsValue stackPropertyValue = errorValue . GetProperty ( stackPropertyId ) ;
274
294
string messageWithTypeAndCallStack = stackPropertyValue . ValueType == JsValueType . String ?
275
- stackPropertyValue . ConvertToString ( ) . ToString ( ) : string . Empty ;
295
+ stackPropertyValue . ToString ( ) : string . Empty ;
276
296
string messageWithType = errorValue . ConvertToString ( ) . ToString ( ) ;
277
297
string rawCallStack = messageWithTypeAndCallStack
278
298
. TrimStart ( messageWithType )
@@ -301,36 +321,45 @@ private WrapperException WrapJsException(OriginalException originalException,
301
321
if ( errorValue . HasProperty ( urlPropertyId ) )
302
322
{
303
323
EdgeJsValue urlPropertyValue = errorValue . GetProperty ( urlPropertyId ) ;
304
- documentName = urlPropertyValue . ConvertToString ( ) . ToString ( ) ;
324
+ documentName = urlPropertyValue . ValueType == JsValueType . String ?
325
+ urlPropertyValue . ToString ( ) : string . Empty ;
305
326
}
306
327
307
328
EdgeJsPropertyId linePropertyId = EdgeJsPropertyId . FromString ( "line" ) ;
308
329
if ( errorValue . HasProperty ( linePropertyId ) )
309
330
{
310
331
EdgeJsValue linePropertyValue = errorValue . GetProperty ( linePropertyId ) ;
311
- lineNumber = linePropertyValue . ConvertToNumber ( ) . ToInt32 ( ) + 1 ;
332
+ lineNumber = linePropertyValue . ValueType == JsValueType . Number ?
333
+ linePropertyValue . ToInt32 ( ) + 1 : 0 ;
312
334
}
313
335
314
336
EdgeJsPropertyId columnPropertyId = EdgeJsPropertyId . FromString ( "column" ) ;
315
337
if ( errorValue . HasProperty ( columnPropertyId ) )
316
338
{
317
339
EdgeJsValue columnPropertyValue = errorValue . GetProperty ( columnPropertyId ) ;
318
- columnNumber = columnPropertyValue . ConvertToNumber ( ) . ToInt32 ( ) + 1 ;
340
+ columnNumber = columnPropertyValue . ValueType == JsValueType . Number ?
341
+ columnPropertyValue . ToInt32 ( ) + 1 : 0 ;
319
342
}
320
343
321
344
string sourceLine = string . Empty ;
322
345
EdgeJsPropertyId sourcePropertyId = EdgeJsPropertyId . FromString ( "source" ) ;
323
346
if ( errorValue . HasProperty ( sourcePropertyId ) )
324
347
{
325
348
EdgeJsValue sourcePropertyValue = errorValue . GetProperty ( sourcePropertyId ) ;
326
- sourceLine = sourcePropertyValue . ConvertToString ( ) . ToString ( ) ;
349
+ sourceLine = sourcePropertyValue . ValueType == JsValueType . String ?
350
+ sourcePropertyValue . ToString ( ) : string . Empty ; ;
327
351
}
328
352
329
353
sourceFragment = TextHelpers . GetTextFragmentFromLine ( sourceLine , columnNumber ) ;
330
354
message = JsErrorHelpers . GenerateScriptErrorMessage ( type , description , documentName ,
331
355
lineNumber , columnNumber , sourceFragment ) ;
332
356
}
333
357
}
358
+ else if ( errorValueType == JsValueType . String )
359
+ {
360
+ message = errorValue . ToString ( ) ;
361
+ description = message ;
362
+ }
334
363
else
335
364
{
336
365
message = errorValue . ConvertToString ( ) . ToString ( ) ;
0 commit comments