Skip to content

Commit 71394d0

Browse files
authored
Rename captureError to recordError (#9431)
1 parent 686b9e1 commit 71394d0

File tree

10 files changed

+56
-54
lines changed

10 files changed

+56
-54
lines changed

common/api-review/crashlytics.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import { AnyValueMap } from '@opentelemetry/api-logs';
88
import { FirebaseApp } from '@firebase/app';
99
import { Instrumentation } from 'next';
1010

11-
// @public
12-
export function captureError(crashlytics: Crashlytics, error: unknown, attributes?: AnyValueMap): void;
13-
1411
// @public
1512
export interface Crashlytics {
1613
app: FirebaseApp;
@@ -33,6 +30,9 @@ export { Instrumentation }
3330
// @public
3431
export function nextOnRequestError(crashlyticsOptions?: CrashlyticsOptions): Instrumentation.onRequestError;
3532

33+
// @public
34+
export function recordError(crashlytics: Crashlytics, error: unknown, attributes?: AnyValueMap): void;
35+
3636

3737
// (No @packageDocumentation comment for this package)
3838

docs-devsite/crashlytics_.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ https://github.com/firebase/firebase-js-sdk
1818
| <b>function(app, ...)</b> |
1919
| [getCrashlytics(app, options)](./crashlytics_.md#getcrashlytics_a9d22a1) | Returns the default [Crashlytics](./crashlytics_.crashlytics.md#crashlytics_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface)<!-- -->. If no instance exists, initializes a new instance with the default settings. |
2020
| <b>function(crashlytics, ...)</b> |
21-
| [captureError(crashlytics, error, attributes)](./crashlytics_.md#captureerror_6824e74) | Enqueues an error to be uploaded to the Firebase Crashlytics API. |
2221
| [flush(crashlytics)](./crashlytics_.md#flush_16fdf66) | Flushes all enqueued Crashlytics data immediately, instead of waiting for default batching. |
22+
| [recordError(crashlytics, error, attributes)](./crashlytics_.md#recorderror_6824e74) | Enqueues an error to be uploaded to the Firebase Crashlytics API. |
2323
| <b>function(crashlyticsOptions, ...)</b> |
2424
| [nextOnRequestError(crashlyticsOptions)](./crashlytics_.md#nextonrequesterror_3caf5de) | Automatically report uncaught errors from server routes to Firebase Crashlytics. |
2525

@@ -71,49 +71,49 @@ const crashlytics = getCrashlytics(app);
7171

7272
## function(crashlytics, ...)
7373

74-
### captureError(crashlytics, error, attributes) {:#captureerror_6824e74}
74+
### flush(crashlytics) {:#flush_16fdf66}
7575

76-
Enqueues an error to be uploaded to the Firebase Crashlytics API.
76+
Flushes all enqueued Crashlytics data immediately, instead of waiting for default batching.
7777

7878
<b>Signature:</b>
7979

8080
```typescript
81-
export declare function captureError(crashlytics: Crashlytics, error: unknown, attributes?: AnyValueMap): void;
81+
export declare function flush(crashlytics: Crashlytics): Promise<void>;
8282
```
8383

8484
#### Parameters
8585

8686
| Parameter | Type | Description |
8787
| --- | --- | --- |
8888
| crashlytics | [Crashlytics](./crashlytics_.crashlytics.md#crashlytics_interface) | The [Crashlytics](./crashlytics_.crashlytics.md#crashlytics_interface) instance. |
89-
| error | unknown | The caught exception, typically an |
90-
| attributes | AnyValueMap | = Optional, arbitrary attributes to attach to the error log |
9189

9290
<b>Returns:</b>
9391

94-
void
92+
Promise&lt;void&gt;
9593

96-
### flush(crashlytics) {:#flush_16fdf66}
94+
a promise which is resolved when all flushes are complete
9795

98-
Flushes all enqueued Crashlytics data immediately, instead of waiting for default batching.
96+
### recordError(crashlytics, error, attributes) {:#recorderror_6824e74}
97+
98+
Enqueues an error to be uploaded to the Firebase Crashlytics API.
9999

100100
<b>Signature:</b>
101101

102102
```typescript
103-
export declare function flush(crashlytics: Crashlytics): Promise<void>;
103+
export declare function recordError(crashlytics: Crashlytics, error: unknown, attributes?: AnyValueMap): void;
104104
```
105105

106106
#### Parameters
107107

108108
| Parameter | Type | Description |
109109
| --- | --- | --- |
110110
| crashlytics | [Crashlytics](./crashlytics_.crashlytics.md#crashlytics_interface) | The [Crashlytics](./crashlytics_.crashlytics.md#crashlytics_interface) instance. |
111+
| error | unknown | The caught exception, typically an Error object |
112+
| attributes | AnyValueMap | Optional, arbitrary attributes to attach to the error log |
111113

112114
<b>Returns:</b>
113115

114-
Promise&lt;void&gt;
115-
116-
a promise which is resolved when all flushes are complete
116+
void
117117

118118
## function(crashlyticsOptions, ...)
119119

packages/crashlytics/src/angular/index.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ describe('FirebaseErrorHandler', () => {
5353

5454
let fakeCrashlytics: Crashlytics;
5555

56-
let captureErrorStub: sinon.SinonStub;
56+
let recordErrorStub: sinon.SinonStub;
5757
let getCrashlyticsStub: sinon.SinonStub;
5858

5959
beforeEach(() => {
6060
app = initializeApp({ projectId: 'p', appId: 'fakeapp' });
6161
fakeCrashlytics = {} as Crashlytics;
6262

63-
captureErrorStub = stub(crashlytics, 'captureError');
63+
recordErrorStub = stub(crashlytics, 'recordError');
6464
getCrashlyticsStub = stub(crashlytics, 'getCrashlytics').returns(
6565
fakeCrashlytics
6666
);
@@ -93,7 +93,7 @@ describe('FirebaseErrorHandler', () => {
9393
const testError = new Error('Test error message');
9494
errorHandler.handleError(testError);
9595
expect(getCrashlyticsStub).to.have.been.called;
96-
expect(captureErrorStub).to.have.been.calledWith(
96+
expect(recordErrorStub).to.have.been.calledWith(
9797
fakeCrashlytics,
9898
testError,
9999
{
@@ -107,8 +107,8 @@ describe('FirebaseErrorHandler', () => {
107107

108108
const testError = new Error('Test error message');
109109
errorHandler.handleError(testError);
110-
expect(captureErrorStub).to.have.been.called;
111-
expect(captureErrorStub).to.have.been.calledWith(
110+
expect(recordErrorStub).to.have.been.called;
111+
expect(recordErrorStub).to.have.been.calledWith(
112112
fakeCrashlytics,
113113
testError,
114114
{

packages/crashlytics/src/angular/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { ErrorHandler, inject } from '@angular/core';
2020
// eslint-disable-next-line import/no-extraneous-dependencies
2121
import { ActivatedRouteSnapshot, Router } from '@angular/router';
2222
import { registerCrashlytics } from '../register';
23-
import { captureError, getCrashlytics } from '../api';
23+
import { recordError, getCrashlytics } from '../api';
2424
import { Crashlytics, CrashlyticsOptions } from '../public-types';
2525
import { FirebaseApp } from '@firebase/app';
2626

@@ -90,7 +90,7 @@ export class FirebaseErrorHandler implements ErrorHandler {
9090
'angular_route_path': this.getSafeRoutePath(this.router)
9191
};
9292

93-
captureError(this.crashlytics, error, attributes);
93+
recordError(this.crashlytics, error, attributes);
9494
}
9595

9696
/**

packages/crashlytics/src/api.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
} from '@firebase/app';
3434
import { Component, ComponentType } from '@firebase/component';
3535
import { FirebaseAppCheckInternal } from '@firebase/app-check-interop-types';
36-
import { captureError, flush, getCrashlytics } from './api';
36+
import { recordError, flush, getCrashlytics } from './api';
3737
import {
3838
LOG_ENTRY_ATTRIBUTE_KEYS,
3939
CRASHLYTICS_SESSION_ID_KEY
@@ -181,13 +181,13 @@ describe('Top level API', () => {
181181
});
182182
});
183183

184-
describe('captureError()', () => {
184+
describe('recordError()', () => {
185185
it('should capture an Error object correctly', () => {
186186
const error = new Error('This is a test error');
187187
error.stack = '...stack trace...';
188188
error.name = 'TestError';
189189

190-
captureError(fakeCrashlytics, error);
190+
recordError(fakeCrashlytics, error);
191191

192192
expect(emittedLogs.length).to.equal(1);
193193
const log = emittedLogs[0];
@@ -205,7 +205,7 @@ describe('Top level API', () => {
205205
const error = new Error('error with no stack');
206206
error.stack = undefined;
207207

208-
captureError(fakeCrashlytics, error);
208+
recordError(fakeCrashlytics, error);
209209

210210
expect(emittedLogs.length).to.equal(1);
211211
const log = emittedLogs[0];
@@ -220,7 +220,7 @@ describe('Top level API', () => {
220220
});
221221

222222
it('should capture a string error correctly', () => {
223-
captureError(fakeCrashlytics, 'a string error');
223+
recordError(fakeCrashlytics, 'a string error');
224224

225225
expect(emittedLogs.length).to.equal(1);
226226
const log = emittedLogs[0];
@@ -233,7 +233,7 @@ describe('Top level API', () => {
233233
});
234234

235235
it('should capture an unknown error type correctly', () => {
236-
captureError(fakeCrashlytics, 12345);
236+
recordError(fakeCrashlytics, 12345);
237237

238238
expect(emittedLogs.length).to.equal(1);
239239
const log = emittedLogs[0];
@@ -259,7 +259,7 @@ describe('Top level API', () => {
259259
span.spanContext().traceId = 'my-trace';
260260
span.spanContext().spanId = 'my-span';
261261

262-
captureError(fakeCrashlytics, error);
262+
recordError(fakeCrashlytics, error);
263263
span.end();
264264
});
265265

@@ -280,7 +280,7 @@ describe('Top level API', () => {
280280
error.stack = '...stack trace...';
281281
error.name = 'TestError';
282282

283-
captureError(fakeCrashlytics, error, {
283+
recordError(fakeCrashlytics, error, {
284284
strAttr: 'string attribute',
285285
mapAttr: {
286286
boolAttr: true,
@@ -315,7 +315,7 @@ describe('Top level API', () => {
315315
appVersion: '1.0.0'
316316
};
317317

318-
captureError(crashlytics, 'a string error');
318+
recordError(crashlytics, 'a string error');
319319

320320
expect(emittedLogs.length).to.equal(1);
321321
const log = emittedLogs[0];
@@ -328,7 +328,7 @@ describe('Top level API', () => {
328328
it('should use auto constants if available', () => {
329329
AUTO_CONSTANTS.appVersion = '1.2.3';
330330

331-
captureError(fakeCrashlytics, 'a string error');
331+
recordError(fakeCrashlytics, 'a string error');
332332

333333
expect(emittedLogs.length).to.equal(1);
334334
const log = emittedLogs[0];
@@ -342,7 +342,7 @@ describe('Top level API', () => {
342342
it('should retrieve existing session ID from sessionStorage', () => {
343343
storage[CRASHLYTICS_SESSION_ID_KEY] = 'existing-session-id';
344344

345-
captureError(fakeCrashlytics, 'error');
345+
recordError(fakeCrashlytics, 'error');
346346

347347
expect(emittedLogs.length).to.equal(1);
348348
const log = emittedLogs[0];
@@ -364,7 +364,7 @@ describe('Top level API', () => {
364364
writable: true
365365
});
366366

367-
captureError(fakeCrashlytics, 'error');
367+
recordError(fakeCrashlytics, 'error');
368368

369369
expect(emittedLogs.length).to.equal(1);
370370
const log = emittedLogs[0];
@@ -385,7 +385,7 @@ describe('Top level API', () => {
385385
writable: true
386386
});
387387

388-
captureError(fakeCrashlytics, 'error');
388+
recordError(fakeCrashlytics, 'error');
389389

390390
expect(emittedLogs.length).to.equal(1);
391391
const log = emittedLogs[0];
@@ -397,8 +397,8 @@ describe('Top level API', () => {
397397

398398
describe('flush()', () => {
399399
it('should flush logs correctly', async () => {
400-
captureError(fakeCrashlytics, 'error1');
401-
captureError(fakeCrashlytics, 'error2');
400+
recordError(fakeCrashlytics, 'error1');
401+
recordError(fakeCrashlytics, 'error2');
402402

403403
expect(emittedLogs.length).to.equal(2);
404404

packages/crashlytics/src/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ export function getCrashlytics(
7171
* @public
7272
*
7373
* @param crashlytics - The {@link Crashlytics} instance.
74-
* @param error - The caught exception, typically an {@link Error}
75-
* @param attributes = Optional, arbitrary attributes to attach to the error log
74+
* @param error - The caught exception, typically an Error object
75+
* @param attributes - Optional, arbitrary attributes to attach to the error log
7676
*/
77-
export function captureError(
77+
export function recordError(
7878
crashlytics: Crashlytics,
7979
error: unknown,
8080
attributes?: AnyValueMap

packages/crashlytics/src/next.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use(chaiAsPromised);
3030

3131
describe('nextOnRequestError', () => {
3232
let getCrashlyticsStub: sinon.SinonStub;
33-
let captureErrorStub: sinon.SinonStub;
33+
let recordErrorStub: sinon.SinonStub;
3434
let fakeApp: FirebaseApp;
3535
let fakeCrashlytics: Crashlytics;
3636

@@ -42,7 +42,7 @@ describe('nextOnRequestError', () => {
4242
getCrashlyticsStub = stub(crashlytics, 'getCrashlytics').returns(
4343
fakeCrashlytics
4444
);
45-
captureErrorStub = stub(crashlytics, 'captureError');
45+
recordErrorStub = stub(crashlytics, 'recordError');
4646
});
4747

4848
afterEach(() => {
@@ -71,7 +71,7 @@ describe('nextOnRequestError', () => {
7171
await nextOnRequestError()(error, errorRequest, errorContext);
7272

7373
expect(getCrashlyticsStub).to.have.been.calledOnceWith(fakeApp);
74-
expect(captureErrorStub).to.have.been.calledOnceWith(
74+
expect(recordErrorStub).to.have.been.calledOnceWith(
7575
fakeCrashlytics,
7676
error,
7777
{

packages/crashlytics/src/next.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { getApp } from '@firebase/app';
19-
import { captureError, getCrashlytics } from './api';
19+
import { recordError, getCrashlytics } from './api';
2020
// eslint-disable-next-line import/no-extraneous-dependencies
2121
import { Instrumentation } from 'next';
2222
import { CrashlyticsOptions } from './public-types';
@@ -52,6 +52,6 @@ export function nextOnRequestError(
5252
'nextjs_route_type': errorContext.routeType
5353
};
5454

55-
captureError(crashlytics, error, attributes);
55+
recordError(crashlytics, error, attributes);
5656
};
5757
}

packages/crashlytics/src/react/index.test.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,18 @@ use(chaiAsPromised);
3232

3333
describe('FirebaseCrashlytics', () => {
3434
let getCrashlyticsStub: sinon.SinonStub;
35-
let captureErrorStub: sinon.SinonStub;
35+
let recordErrorStub: sinon.SinonStub;
3636
let fakeApp: FirebaseApp;
3737
let fakeCrashlytics: Crashlytics;
3838

3939
beforeEach(() => {
4040
fakeApp = { name: 'fakeApp' } as FirebaseApp;
4141
fakeCrashlytics = {} as Crashlytics;
4242

43-
getCrashlyticsStub = stub(crashlytics, 'getCrashlytics').returns(fakeCrashlytics);
44-
captureErrorStub = stub(crashlytics, 'captureError');
43+
getCrashlyticsStub = stub(crashlytics, 'getCrashlytics').returns(
44+
fakeCrashlytics
45+
);
46+
recordErrorStub = stub(crashlytics, 'recordError');
4547
});
4648

4749
afterEach(() => {
@@ -57,7 +59,7 @@ describe('FirebaseCrashlytics', () => {
5759
window.addEventListener('error', (event: ErrorEvent) => {
5860
// Registers another listener (sequential) to confirm behaviour.
5961
expect(getCrashlyticsStub).to.have.been.calledWith(fakeApp);
60-
expect(captureErrorStub).to.have.been.calledWith(fakeCrashlytics, error);
62+
expect(recordErrorStub).to.have.been.calledWith(fakeCrashlytics, error);
6163
done();
6264
});
6365
window.dispatchEvent(new ErrorEvent('error', { error }));
@@ -72,6 +74,6 @@ describe('FirebaseCrashlytics', () => {
7274
new PromiseRejectionEvent('unhandledrejection', { reason, promise })
7375
);
7476
expect(getCrashlyticsStub).to.have.been.calledWith(fakeApp);
75-
expect(captureErrorStub).to.have.been.calledWith(fakeCrashlytics, reason);
77+
expect(recordErrorStub).to.have.been.calledWith(fakeCrashlytics, reason);
7678
});
7779
});

packages/crashlytics/src/react/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { FirebaseApp } from '@firebase/app';
1919
import { registerCrashlytics } from '../register';
20-
import { captureError, getCrashlytics } from '../api';
20+
import { recordError, getCrashlytics } from '../api';
2121
import { CrashlyticsOptions } from '../public-types';
2222
import { useEffect } from 'react';
2323

@@ -84,11 +84,11 @@ export function FirebaseCrashlytics({
8484
}
8585

8686
const errorListener = (event: ErrorEvent): void => {
87-
captureError(crashlytics, event.error, {});
87+
recordError(crashlytics, event.error, {});
8888
};
8989

9090
const unhandledRejectionListener = (event: PromiseRejectionEvent): void => {
91-
captureError(crashlytics, event.reason, {});
91+
recordError(crashlytics, event.reason, {});
9292
};
9393

9494
try {

0 commit comments

Comments
 (0)