Skip to content

Error logging: logErrorIfNeeded no longer prints message if it's the same as the error description#1776

Merged
NachoSoto merged 4 commits into
mainfrom
error-logging-message
Jul 28, 2022
Merged

Error logging: logErrorIfNeeded no longer prints message if it's the same as the error description#1776
NachoSoto merged 4 commits into
mainfrom
error-logging-message

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Jul 27, 2022

Copy link
Copy Markdown
Contributor

Working on SDKONCALL-62 I realized that there are many instances where we end up logging the same message twice.

This PR not only improves the logic, but adds much needed test coverage to ErrorUtils.logErrorIfNeeded and error logging in general.

@NachoSoto NachoSoto requested a review from a team July 27, 2022 19:20
Comment thread Tests/UnitTests/Purchasing/ErrorCodeTests.swift Outdated
…e same as the error description

Working on [SDKONCALL-62] I realized that there are many instances where we end up logging the same message twice.

This PR not only improves the logic, but adds much needed test coverage to `ErrorUtils.logErrorIfNeeded` and error logging in general.
@NachoSoto NachoSoto force-pushed the error-logging-message branch from 8bf0e45 to 5582a89 Compare July 27, 2022 21:01
@NachoSoto NachoSoto added the pr:fix A bug fix label Jul 27, 2022

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few questions but LGTM!

Comment thread Tests/UnitTests/Purchasing/ErrorCodeTests.swift Outdated
Comment thread Tests/UnitTests/Purchasing/ErrorCodeTests.swift Outdated
Comment thread Tests/UnitTests/Purchasing/ErrorCodeTests.swift Outdated
@NachoSoto NachoSoto merged commit f8113a7 into main Jul 28, 2022
@NachoSoto NachoSoto deleted the error-logging-message branch July 28, 2022 15:11
This was referenced Aug 1, 2022
NachoSoto added a commit that referenced this pull request Aug 1, 2022
### Fixes:
* `CustomerInfoResponseHandler`: return `CustomerInfo` instead of error if the response was successful (#1778) via NachoSoto (@NachoSoto)
* Error logging: `logErrorIfNeeded` no longer prints message if it's the same as the error description (#1776) via NachoSoto (@NachoSoto)
* fix another broken link in docC docs (#1777) via aboedo (@aboedo)
* fix links to restorePurchase (#1775) via aboedo (@aboedo)
* fix getProducts docs broken link (#1772) via aboedo (@aboedo)

### Improvements:
* `Logger`: wrap `message` in `@autoclosure` to avoid creating when `LogLevel` is disabled (#1781) via NachoSoto (@NachoSoto)

### Other changes:
* Lint: fixed `SubscriberAttributesManager` (#1774) via NachoSoto (@NachoSoto)
NachoSoto added a commit that referenced this pull request Aug 17, 2022
Follow up to #1776. That PR added a lot of tests to cover error logging, and #1778 introduced a small error that wasn't covered: if attribute errors are empty, the `localizedDescription` could end up becoming `"[:]"`. This fixes that.

## Examples:

This was the underlying error returned (the output of `error.localizedDescription`):

#### Before:
> [:]
#### After:
> There was a credentials issue. Check the underlying error for more details.

And this is what was logged (notice that I also fixed `ErrorCode.invalidCredentialsError` to not log as an "Apple Error"):

#### Before:
> 🍎‼️There was a credentials issue. Check the underlying error for more details. [:]
#### After:
> 😿‼️ There was a credentials issue. Check the underlying error for more details.
NachoSoto added a commit that referenced this pull request Aug 17, 2022
Follow up to #1776. That PR added a lot of tests to cover error logging, and #1778 introduced a small error that wasn't covered: if attribute errors are empty, the `localizedDescription` could end up becoming `"[:]"`. This fixes that.

## Examples:

This was the underlying error returned (the output of `error.localizedDescription`):

#### Before:
> [:]
#### After:
> There was a credentials issue. Check the underlying error for more details.

And this is what was logged (notice that I also fixed `ErrorCode.invalidCredentialsError` to not log as an "Apple Error"):

#### Before:
> 🍎‼️There was a credentials issue. Check the underlying error for more details. [:]
#### After:
> 😿‼️ There was a credentials issue. Check the underlying error for more details.
NachoSoto added a commit that referenced this pull request Oct 11, 2022
…underlying errors (#1974)

## Changes:
- `Error.localizedDescription` now matches the message being logged.
Improvements introduced in #1776, for example, now apply to the
description too.
- Logged `BackendError` messages now include underlying error.

## Examples:

The following errors are improved:

### `BackendError`:
- Before:
>  😿‼️ There was an unknown backend error.

- After:
> 😿‼️ There was an unknown backend error. Page not found

### API key error:
- Before:
> 😿‼️ There was a credentials issue. Check the underlying error for more
details.

- After:
> 😿‼️ There was a credentials issue. Check the underlying error for more
details. Invalid API key

### Attribute errors:
- Before:
> ["$email": "invalid"]

- After:
> One or more of the attributes sent could not be saved. ["$email":
"invalid"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants