-
-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationgood first issueGood for newcomersGood for newcomers
Description
Description
The error classes in src/errors.ts
currently lack unit tests. This is a critical gap in our test coverage that needs to be addressed to ensure these foundational error handling components work correctly.
What needs to be done
Create comprehensive unit tests that verify:
- Constructor properly sets all error properties (
error
,error_description
,error_uri
) - Error inheritance from native
Error
class works correctly - Default messages are applied when not provided
- Error name is set correctly to "OAuthError" and "TimeoutError"
- The error stack trace is properly maintained
- Serialization behavior (what happens with
JSON.stringify
)
Why this matters
Error handling is a critical part of OAuth flows. Without proper tests, we can't guarantee:
- Errors are properly caught and identified in try/catch blocks
- Error messages provide useful debugging information
- The error properties match OAuth 2.0 specifications
Implementation considerations
- Edge cases: What happens with extremely long error descriptions? Unicode characters? Null/undefined values?
- Error comparison: Should we test error equality? How do we handle error comparison in tests?
- Alternative approach: Consider whether we should use a more sophisticated error hierarchy with specific error types (e.g.,
AccessDeniedError
,InvalidScopeError
) instead of a genericOAuthError
- Error recovery: Should these errors include recovery suggestions or links to documentation?
Files to modify/create
- Create:
src/errors.test.ts
- Reference:
src/errors.ts
Example test structure
import { expect, test, describe } from "bun:test";
import { OAuthError, TimeoutError } from "./errors";
describe("OAuthError", () => {
test("should set properties correctly", () => {
const error = new OAuthError("access_denied", "User denied access", "https://example.com/error");
expect(error.error).toBe("access_denied");
expect(error.error_description).toBe("User denied access");
expect(error.error_uri).toBe("https://example.com/error");
expect(error.name).toBe("OAuthError");
});
// Add more comprehensive tests...
});
Skills required
- TypeScript
- Testing with Bun
- Understanding of error handling patterns
Difficulty
Easy - This is a great first issue for someone new to the codebase!
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationgood first issueGood for newcomersGood for newcomers