|
| 1 | +import {describe, expect, it} from 'vitest'; |
| 2 | + |
| 3 | +import {processErrorIntoDetails} from './global-errors'; |
| 4 | + |
| 5 | +describe('processErrorIntoDetails', () => { |
| 6 | + it('splits a .NET error at the first stack frame', () => { |
| 7 | + const message = [ |
| 8 | + 'System.InvalidOperationException: Everything is broken.', |
| 9 | + ' at FwLiteShared.Services.Foo.Bar(String x)', |
| 10 | + ' at FwLiteShared.Services.Foo.Baz()', |
| 11 | + ].join('\n'); |
| 12 | + |
| 13 | + const {message: title, detail} = processErrorIntoDetails({message, error: null}); |
| 14 | + |
| 15 | + expect(title).toBe('System.InvalidOperationException: Everything is broken.'); |
| 16 | + expect(detail).toContain('at FwLiteShared.Services.Foo.Bar(String x)'); |
| 17 | + }); |
| 18 | + |
| 19 | + it('splits at the inner-exception marker that precedes the outer frames, keeping a wrapped error\'s title short', () => { |
| 20 | + // MSAL wrapping an Android network failure: the whole " ---> " cascade comes before the first managed frame |
| 21 | + const message = [ |
| 22 | + 'Microsoft.Identity.Client.MsalServiceException: Failed to retrieve OIDC configuration. See inner exception.', |
| 23 | + ' ---> System.Net.Http.HttpRequestException: Connection failure', |
| 24 | + ' ---> Java.Net.UnknownHostException: Unable to resolve host', |
| 25 | + ' at Java.Interop.JniEnvironment.InstanceMethods.CallVoidMethod()', |
| 26 | + ].join('\n'); |
| 27 | + |
| 28 | + const {message: title, detail} = processErrorIntoDetails({message, error: null}); |
| 29 | + |
| 30 | + expect(title).toBe('Microsoft.Identity.Client.MsalServiceException: Failed to retrieve OIDC configuration. See inner exception.'); |
| 31 | + expect(detail).toContain('---> System.Net.Http.HttpRequestException: Connection failure'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('keeps the whole message as the title when there is no .NET stack', () => { |
| 35 | + const {message: title, detail} = processErrorIntoDetails({message: 'plain error', error: null}); |
| 36 | + |
| 37 | + expect(title).toBe('plain error'); |
| 38 | + expect(detail).toBeUndefined(); |
| 39 | + }); |
| 40 | + |
| 41 | + it('does not repeat a JS Error message in both title and detail', () => { |
| 42 | + const error = new Error('boom'); |
| 43 | + |
| 44 | + const {message: title, detail} = processErrorIntoDetails({message: 'Uncaught Error: boom', error}); |
| 45 | + |
| 46 | + expect(title).toBe('boom'); |
| 47 | + expect(detail).not.toContain('boom'); |
| 48 | + expect(detail).toContain('at '); |
| 49 | + }); |
| 50 | +}); |
0 commit comments