Skip to content

ErrorUtils: improved logging and localizedDescription to include underlying errors#1974

Merged
NachoSoto merged 2 commits into
mainfrom
error-utils-underlying-errors
Oct 11, 2022
Merged

ErrorUtils: improved logging and localizedDescription to include underlying errors#1974
NachoSoto merged 2 commits into
mainfrom
error-utils-underlying-errors

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Oct 10, 2022

Copy link
Copy Markdown
Contributor

Changes:

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"]

…Convertible`

This allows methods throwing something like `BackendError` and converting it to `PurchasesError` automatically.
@NachoSoto NachoSoto added the pr:fix A bug fix label Oct 10, 2022
@NachoSoto NachoSoto requested a review from a team October 10, 2022 18:57
…underlying errors

- `Error.localizedDescription` now matches the message being logged

The following errors are improved:

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

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

- 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

- Before:
> ["$email": "invalid"]

- After:
> One or more of the attributes sent could not be saved. ["$email": "invalid"]
Base automatically changed from error-utils-untyped-purchases-error to main October 11, 2022 19:50
@NachoSoto NachoSoto merged commit ae22f6e into main Oct 11, 2022
@NachoSoto NachoSoto deleted the error-utils-underlying-errors branch October 11, 2022 19:56
NachoSoto added a commit that referenced this pull request Oct 11, 2022
Finishes [CSDK-451].
This new small public API allows users to quickly figure out if everything in the SDK is correctly configured in a simple way:
```swift
let tester = SDKTester.default
do {
  try await tester.test()
} catch {
  print(error)
}
```

The specific underlying errors will provide information about what failed.

We can continue growing this to check for more specific things, but for now it does 4 things:
- Verify API connectivity: networking issues, firewalling, etc.
- Verify API key is correct
- Verify `Offerings` are configured correctly
- Verify that all products in `Offerings` are configured correctly and found in `StoreKit`

This new API is covered by:
- API testers
- Unit tests
- Integration tests (both on `SK1` and `SK2`)

- #1970
- #1971
- #1973
- #1974
- #1975
- #1976
NachoSoto added a commit that referenced this pull request Oct 14, 2022
Finishes [CSDK-451].
This new small public API allows users to quickly figure out if everything in the SDK is correctly configured in a simple way:
```swift
let tester = SDKTester.default
do {
  try await tester.test()
} catch {
  print(error)
}
```

The specific underlying errors will provide information about what failed.

We can continue growing this to check for more specific things, but for now it does 4 things:
- Verify API connectivity: networking issues, firewalling, etc.
- Verify API key is correct
- Verify `Offerings` are configured correctly
- Verify that all products in `Offerings` are configured correctly and found in `StoreKit`

This new API is covered by:
- API testers
- Unit tests
- Integration tests (both on `SK1` and `SK2`)

- #1970
- #1971
- #1973
- #1974
- #1975
- #1976
NachoSoto added a commit that referenced this pull request Oct 27, 2022
Finishes [CSDK-451].
This new small public API allows users to quickly figure out if everything in the SDK is correctly configured in a simple way:
```swift
let tester = SDKTester.default
do {
  try await tester.test()
} catch {
  print(error)
}
```

The specific underlying errors will provide information about what failed.

We can continue growing this to check for more specific things, but for now it does 4 things:
- Verify API connectivity: networking issues, firewalling, etc.
- Verify API key is correct
- Verify `Offerings` are configured correctly
- Verify that all products in `Offerings` are configured correctly and found in `StoreKit`

This new API is covered by:
- API testers
- Unit tests
- Integration tests (both on `SK1` and `SK2`)

- #1970
- #1971
- #1973
- #1974
- #1975
- #1976
NachoSoto added a commit that referenced this pull request Oct 27, 2022
…errors (#1977)

Finishes [CSDK-451].

This new small public API allows users to quickly figure out if
everything in the SDK is correctly configured in a simple way:
```swift
let diagnostics = PurchasesDiagnostics.default
do {
    try await diagnostics.testSDKHealth()
} catch {
    print(error)
}
```

The specific underlying errors will provide information about what
failed.

We can continue growing this to check for more specific things, but for
now it does 4 things:
- Verify API connectivity: networking issues, firewalling, etc.
- Verify API key is correct
- Verify `Offerings` are configured correctly
- Verify that all products in `Offerings` are configured correctly and
found in `StoreKit`

This new API is covered by:
- API testers
- Unit tests
- Integration tests (both on `SK1` and `SK2`)

_I've taken the "shortcut" of making this `async` only (while still
compatible with Objective-C), which means it's not compatible with iOS
12.x. But that made the implementation a lot simpler, which I think is a
useful tradeoff._

### Depends on:
- #1970
- #1971
- #1973
- #1974
- #1975
- #1976

[CSDK-451]:
https://revenuecats.atlassian.net/browse/CSDK-451?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
NachoSoto added a commit that referenced this pull request Jul 23, 2023
… description

This has been improved significantly (like #1974). I wrote these tests to see if I could reproduce why the logs in RevenueCat/purchases-flutter#766 don't include the underlying error.
It's likely that's using an old version of the SDK, but these tests are still useful.
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