6

I built up this regex at http://regextester.com to parse YSOD but VS is complaining about a syntax error. I am sure I am missing an escape somewhere but I am coming up blank.

Here is is in original form. any help is appreciated.

var rxYSOD = /<!--\s*\[(.*?)]:(\s*.*\s(.*\n)*?)\s*(at(.*\n)*)-->/gs;

UPDATE: Kobi pointed out the obvious and got me moving again. For those who are interested, this is valid JavaScript to test and parse an XMLHttpRequest.responseText for an ASP.net Yellow Screen Of Death (YSOD).

var rxYSOD = /<!--\s*\[(.*?)]:(\s*.*\s(.*[\n\r]*)*?)\s*(at(.*[\n\r]*)*)-->/;
if (rxYSOD.test(text)) {
    // looks like one..
    var ysod = rxYSOD.exec(text);
    errObj = { Message: ysod[2], StackTrace: ysod[4], ExceptionType: ysod[1] };
}

@Kobi - This is the result and the reason I want to parse the html even though I get a 500:

{
 "message": " Unknown web method ValidateUser.\r\nParameter name: methodName\r\n",
 "stackTrace": "at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)\r\n   at System.Web.Script.Services.RestHandler.CreateHandler(WebServiceData webServiceData, String methodName)\r\n   at System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context)\r\n   at System.Web.Script.Services.RestHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)\r\n   at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)\r\n   at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)\r\n   at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()\r\n   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)\r\n",
 "exceptionType": "ArgumentException",
 "errorObject": {
  "Message": " Unknown web method ValidateUser.\r\nParameter name: methodName\r\n",
  "StackTrace": "at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)\r\n   at System.Web.Script.Services.RestHandler.CreateHandler(WebServiceData webServiceData, String methodName)\r\n   at System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context)\r\n   at System.Web.Script.Services.RestHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)\r\n   at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)\r\n   at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)\r\n   at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()\r\n   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)\r\n",
  "ExceptionType": "ArgumentException"
 },
 "statusCode": 500,
 "servicePath": "/Authentication_JSON_AppService.axd",
 "useGet": false,
 "params": {
  "username": "testingUser",
  "password": "testingUser",
  "customCredential": null
 },
 "methodName": "ValidateUser",
 "__typeName": "Salient.ScriptModel.WebServiceError"
}
skaffman
  • 398,947
  • 96
  • 818
  • 769
Sky Sanders
  • 36,396
  • 8
  • 69
  • 90
  • Won't you also get status code `500 Internal Server Error` for these screens? Anyway, good luck! – Kobi Feb 28 '10 at 11:49
  • @Kobi, Yeah, sure do. thats why I am parsing the page out as it has the actual exception. Nothing I hate worse is a catch all exception message when the information is actually available. – Sky Sanders Feb 28 '10 at 11:57

2 Answers2

4

Firefox says:

Error: invalid regular expression flag s
Source Code:
var rxYSOD = /<!--\s*\[(.*?)]:(\s*.*\s(.*\n)*?)\s*(at(.*\n)*)-->/gs; 

After removing the s it seems ok (of course, it isn't tested, just parsed correctly).

Kobi
  • 135,331
  • 41
  • 252
  • 292
2

The flag s is invalid in Javascript. To replace, use the replace method.

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452