[PR #327] [CLOSED] Remove ModelError in favour of strongly-typed errors #398

Closed
opened 2026-02-27 20:24:34 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ramsayleung/rspotify/pull/327
Author: @SabrinaJewson
Created: 6/15/2022
Status: Closed

Base: masterHead: no-model-error


📝 Commits (6)

  • da97c4d Remove ModelError in favour of strongly-typed errors
  • e632496 Remove ClientError::CacheFile
  • 0b1f78c Document ModelError removal in changelog
  • 5678cf1 Use derive(Error) instead of manual impls
  • 48a3e6d Use American English and wrap comments
  • 5894f97 Merge branch 'master' into no-model-error

📊 Changes

6 files changed (+126 additions, -34 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 rspotify-model/src/auth.rs (+117 -16)
📝 rspotify-model/src/error.rs (+0 -11)
📝 src/client_creds.rs (+2 -1)
📝 src/clients/oauth.rs (+4 -1)
📝 src/lib.rs (+2 -5)

📄 Description

Description

  • Removed ModelError
  • Added ReadTokenCacheError and WriteTokenCacheError
  • To support the above two types, added ReadFileError and WriteFileError
  • Replaced ClientError::Model with the more explicit and useful ClientError::UpdateTokenCache
  • Also removed ClientError::CacheFile, which seems to have been left in by accident

Motivation and Context

Strongly-typed errors are better than weakly typed errors because:

  • They make it easier for the user to see exactly what can go wrong through just types
  • They give better error messages

For example, printing the backtrace of one of the new error types might give this:

Error: failed to read token from cache

Caused by:
0: failed to read file token_cache.json
1: No such file or directory (os error 2)

Which is extremely helpful to the user.

Dependencies

None.

Type of change

Please delete options that are not relevant.

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How has this been tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.

Please also list any relevant details for your test configuration

  • Test A: cargo test --features env-file

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ramsayleung/rspotify/pull/327 **Author:** [@SabrinaJewson](https://github.com/SabrinaJewson) **Created:** 6/15/2022 **Status:** ❌ Closed **Base:** `master` ← **Head:** `no-model-error` --- ### 📝 Commits (6) - [`da97c4d`](https://github.com/ramsayleung/rspotify/commit/da97c4ded2ce778ec0f4df9e3ff14252f00764b2) Remove `ModelError` in favour of strongly-typed errors - [`e632496`](https://github.com/ramsayleung/rspotify/commit/e6324963fa2041352524a2136d0e5c03866c2d23) Remove `ClientError::CacheFile` - [`0b1f78c`](https://github.com/ramsayleung/rspotify/commit/0b1f78ca556ac13a2823ae00cf59c879101be74c) Document `ModelError` removal in changelog - [`5678cf1`](https://github.com/ramsayleung/rspotify/commit/5678cf110e0637eb9ab6013569fb98988d2fd1fe) Use `derive(Error)` instead of manual impls - [`48a3e6d`](https://github.com/ramsayleung/rspotify/commit/48a3e6d2e49a36c9bdec775bfd0d9b03515ffe61) Use American English and wrap comments - [`5894f97`](https://github.com/ramsayleung/rspotify/commit/5894f97cbe720b026d05f2d65fc7d58c35cc25a6) Merge branch 'master' into no-model-error ### 📊 Changes **6 files changed** (+126 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `rspotify-model/src/auth.rs` (+117 -16) 📝 `rspotify-model/src/error.rs` (+0 -11) 📝 `src/client_creds.rs` (+2 -1) 📝 `src/clients/oauth.rs` (+4 -1) 📝 `src/lib.rs` (+2 -5) </details> ### 📄 Description ## Description * Removed `ModelError` * Added `ReadTokenCacheError` and `WriteTokenCacheError` * To support the above two types, added `ReadFileError` and `WriteFileError` * Replaced `ClientError::Model` with the more explicit and useful `ClientError::UpdateTokenCache` * Also removed `ClientError::CacheFile`, which seems to have been left in by accident ## Motivation and Context Strongly-typed errors are better than weakly typed errors because: * They make it easier for the user to see exactly what can go wrong through just types * They give better error messages For example, printing the backtrace of one of the new error types might give this: ``` Error: failed to read token from cache Caused by: 0: failed to read file token_cache.json 1: No such file or directory (os error 2) ``` Which is extremely helpful to the user. ## Dependencies None. ## Type of change Please delete options that are not relevant. - [x] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [x] This change requires a documentation update ## How has this been tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration - [x] Test A: `cargo test --features env-file` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:24:34 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/rspotify#398
No description provided.