TWebSentry and Exceptions on app start

When I use TWebSentry I do not get the exception I am trying to record:

procedure TMainData.SentryErrorProc(E: Exception; const AComment: string; var AHandled: boolean; const CallUIHandler: boolean);
var
  sendException: TJSObject;
begin
  sendException := TJSObject(E);
  WebSentry1.CaptureException(sendException, AComment);

  if CallUIHandler and Assigned(FErrorProc) then
  begin
     {$IFDEF RELEASE}
     FErrorProc('There has been an error and the developers have been notified');
     {$ELSE}
     FErrorProc('Error: ' + E.Message + '. Logged at WebSentry');
     {$ENDIF}
  end;

end;

But the following

TypeError
Cannot read properties of undefined (reading 'hasOwnProperty')

The place it points to in the JS is

rtl.module("WEBLib.Sentry",["System","Classes","SysUtils","Web","WEBLib.Controls","JS","libsentry"],function () {..}

and the code issueing the exception

if ((hint.originalException !== null) && hint.originalException.hasOwnProperty("fHelpContext")) {
          isUncaughtDelphiException = !hint.hasOwnProperty("syntheticException");
          if ($Self.fEnabled) {
            extraData["FromDelphi"] = "yes";
            extraData["UncaughtException"] = isUncaughtDelphiException;
            Sentry.captureException(hint.originalException["FJSError"],pas.JS.New(["extra",extraData]));
          };

Any ideas? Thanks.

Do you have the Sentry script lib added to your project HTML:

<script src="https://browser.sentry-cdn.com/5.17.0/bundle.min.js" crossorigin="anonymous"></script>

Yes it is added, actually it is

<script src="https://browser.sentry-cdn.com/5.22.3/bundle.min.js" type="text/javascript"></script>

I retested the demo and could not see any issue. So please check & compare with the demo.

I have tested the demo and get the same result. I am using WebCore 2.0.5.0. Delphi 11.2 (I'll try the 2.1 beta) and it seems to be on the Delphi Exceptions that the TypeError is actually raised

Catch Delphi Error and Send to Sentry: TypeError
Catch JS Error and Send to Sentry: Error - this looks ok
Raise Delphi Exception Uncaught: TypeError
Throw JS Error Uncaught: Error - this looks ok
Send Log Message to Sentry: works as expected

This is the Web Sentry screen with last test first (so above list inverted)

Screenshot 2023-01-21 103823

The browser for the TypeError shows

Screenshot 2023-01-21 102149

I Have tried with the beta version and still get the same outcomes

I still cannot see an issue here.
Do you use the proper API key?
What browser do you use?
Can you check your browser console for full log of what is happening?

I have a colleague giving it a go and he gets the same TypeError rather than the raised excpetion. What do your test results in WebSentry look like?

Yes, API / DNS is correct
Browser: Edge

On the Delphi Uncaught Exception the console shows the correct exception:

USentry.pas:102 
 Uncaught 
{fMessage: 'Unexpected Delphi Error (uncaught)', fHelpContext: 0}
fHelpContext
: 
0
fMessage
: 
"Unexpected Delphi Error (uncaught)"
[[Prototype]]
: 
Object
btRaiseDelphiErrorClick	@	USentry.pas:102
cb	                    @	rtl.js:240
Click	                @	WEBLib.Controls.pas:1747
HandleDoClick	        @  	WEBLib.Controls.pas:3744
cb	                    @	rtl.js:236

And Web Sentry displays the following and shows as handled

I've now run this on a webserver so we can get the mapped Delphi files. WebSentry now shows this:


TypeError
Cannot read properties of undefined (reading 'hasOwnProperty')

../../../../../Core Source/WEBLib.Sentry.pas in parameters at line 112:43

                    extraData := TJSObject.New;

                 // hint.originalException may be a JS Error Object or a Delphi
                 // error object. So we identify it.
                 if (hint.originalException <> nil) and
                    **hint.originalException.hasOwnProperty('fHelpContext')**
                 then
                 begin
                   // Identified that this is a Delphi object

                   // flag sent as additional data, just for information

Line 112 highlighted (marked for reference)

I cannot see any error here in the console.
I can only suspect there are issues loading the Sentry lib.
Check in your browser console under Networking to see if it loads the Sentry related files properly:

Which Sentry lib are you referring to? My network trace is below. One difference I can see is that YOur TMSWeb_Sentry.js is 325kb and mine is 2.1mb.

After clearing the cache here, this is the detailed network traffic we get from our working demo:

What WebCore version are you running? And is yours a debug build?

I'm building in debug mode with WebCore 2.0.5.0 on Delphi 11.2

On a cleared cache, private window I get

Stepping through the code:

when the button is clicked it calls

WebSentry1.CaptureException(sendException, edRemark.Text);

which calls

TJSSentry.captureException(anObj)

tracked this trough to the point it calls WebLib.Sentry.pas: TSentry.Init. It passes the condition (line 111 in my source)

 if (hint.originalException <> nil) and
    hint.originalException.hasOwnProperty('fHelpContext')

sets the variable

isUncaughtDelphiException := not hint.hasOwnProperty('syntheticException');

is set and it steps into the if Enabled condition where it sets

extraData['FromDelphi'] := 'yes';
extraData['UncaughtException'] := isUncaughtDelphiException;

which calls (so recalling the original process but with a new TJSObject)

  TJSSentry.captureException(
       TJSObject(hint.originalException['FJSError']),
       New([
           'extra', extraData
  ]));

This now comes back into TSentry.Init (line 111) where hint.originalException is now undefined

This then ends up in baseclient.ts via syncPromise.ts (mapped from bundle.min.js) and calls the following

reject(
    `Event processing pipeline threw an error, original event will not be sent. Details have been sent as 
 a new event.\nReason: ${reason}`,
  );

Which is why the new Exception (TypeError) is created.

I can email you the url to our test environment if that would help.

@brunofierens can you share an image of what you see in WebSentry after clicking one of the Delphi buttons on the demo?

This is from my test yesterday

So you are having the same problem.

The TypeError is not the exception raised by the Exception.Create call but the Exception created in failing to process the exception. Note the description

Cannot read properties of undefined (reading 'hasOwnProperty')

That is an exception in the exception handler.

I totally misunderstood. I thought you weren't able to log any exception at all from the beginning and this set me on the wrong foot.
I'll need to check if this way the exception is reported in Sentry is unexpected or not.

That's ok.

If you actually step through the code you will see that the exception raises an exception. That of course is not useful as whatever the actual exception you always get the secondary one and no data from the real exception. It has nothing to do with how WebSentry reports it, it is what is sent.

@brunofierens any progress on this?

I've tried bypassing the issue with

if sendException.hasOwnProperty('fHelpContext') then
begin
  asm
    delete sendException.fHelpContext;
    end;  
end;

But it still doesn't report the error properly.

Thanks