Skip to content

Commit

Permalink
feat: generic type for sfError.data
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Nov 20, 2023
1 parent 74313c7 commit 49beee5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/sfError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { hasString, isString, JsonMap } from '@salesforce/ts-types';
* throw new SfError(message.getMessage('myError'), 'MyErrorName');
* ```
*/
export class SfError extends NamedError {
export class SfError<T = unknown> extends NamedError {
/**
* Action messages. Hints to the users regarding what can be done to fix related issues.
*/
Expand All @@ -41,7 +41,7 @@ export class SfError extends NamedError {
public context?: string;

// Additional data helpful for consumers of this error. E.g., API call result
public data?: unknown;
public data?: T;

/**
* Some errors support `error.code` instead of `error.name`. This keeps backwards compatability.
Expand Down Expand Up @@ -121,7 +121,7 @@ export class SfError extends NamedError {
*
* @param data The payload data.
*/
public setData(data: unknown): SfError {
public setData(data: T): SfError {
this.data = data;
return this;
}
Expand All @@ -142,8 +142,7 @@ export class SfError extends NamedError {
}

if (this.data) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
obj.data = this.data as any;
obj.data = this.data;
}

return obj;
Expand Down

3 comments on commit 49beee5

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: 49beee5 Previous: 715b364 Ratio
Child logger creation 483669 ops/sec (±2.01%) 485375 ops/sec (±1.70%) 1.00
Logging a string on root logger 842145 ops/sec (±5.99%) 783573 ops/sec (±7.93%) 0.93
Logging an object on root logger 629052 ops/sec (±7.36%) 587367 ops/sec (±8.14%) 0.93
Logging an object with a message on root logger 4399 ops/sec (±217.36%) 9739 ops/sec (±201.50%) 2.21
Logging an object with a redacted prop on root logger 382134 ops/sec (±11.46%) 394628 ops/sec (±8.73%) 1.03
Logging a nested 3-level object on root logger 358470 ops/sec (±9.43%) 379211 ops/sec (±8.85%) 1.06

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - ubuntu-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 49beee5 Previous: 715b364 Ratio
Logging an object with a message on root logger 4399 ops/sec (±217.36%) 9739 ops/sec (±201.50%) 2.21

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - windows-latest

Benchmark suite Current: 49beee5 Previous: 715b364 Ratio
Child logger creation 343714 ops/sec (±0.53%) 340711 ops/sec (±0.59%) 0.99
Logging a string on root logger 804844 ops/sec (±4.70%) 819274 ops/sec (±4.83%) 1.02
Logging an object on root logger 626407 ops/sec (±5.30%) 640330 ops/sec (±5.60%) 1.02
Logging an object with a message on root logger 4888 ops/sec (±211.41%) 2627 ops/sec (±228.47%) 0.54
Logging an object with a redacted prop on root logger 454665 ops/sec (±8.85%) 441397 ops/sec (±14.49%) 0.97
Logging a nested 3-level object on root logger 324047 ops/sec (±5.19%) 328734 ops/sec (±5.98%) 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.