-
Notifications
You must be signed in to change notification settings - Fork 3
fix: update-storage-client-error-handling #510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| '@forgerock/davinci-client': patch | ||
| '@forgerock/sdk-utilities': patch | ||
| '@forgerock/storage': patch | ||
| --- | ||
|
|
||
| Fix error handling in storage client and davinci-client | ||
|
|
||
| - Add `isGenericError` type guard to sdk-utilities for runtime error validation | ||
| - Fix storage client to properly catch errors from custom storage implementations, honoring the errors-as-values contract | ||
| - Improve davinci-client error handling to use explicit error checks instead of try-catch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,9 @@ | |
| { | ||
| "path": "../sdk-effects/storage" | ||
| }, | ||
| { | ||
| "path": "../sdk-utilities" | ||
| }, | ||
| { | ||
| "path": "../sdk-types" | ||
| }, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
packages/sdk-utilities/src/lib/error/error.utils.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| /* | ||
| * Copyright (c) 2025 Ping Identity Corporation. All rights reserved. | ||
| * | ||
| * This software may be modified and distributed under the terms | ||
| * of the MIT license. See the LICENSE file for details. | ||
| */ | ||
|
|
||
| import { describe, it, expect } from 'vitest'; | ||
| import { isGenericError } from './error.utils.js'; | ||
| import type { GenericError } from '@forgerock/sdk-types'; | ||
|
|
||
| describe('isGenericError', () => { | ||
| describe('success cases', () => { | ||
| it('isGenericError_ValidGenericErrorWithRequiredFields_ReturnsTrue', () => { | ||
| // Arrange | ||
| const error: GenericError = { | ||
| error: 'storage_error', | ||
| type: 'unknown_error', | ||
| }; | ||
|
|
||
| // Act | ||
| const result = isGenericError(error); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it('isGenericError_ValidGenericErrorWithAllFields_ReturnsTrue', () => { | ||
| // Arrange | ||
| const error: GenericError = { | ||
| code: 500, | ||
| error: 'storage_error', | ||
| message: 'Failed to store value', | ||
| status: 500, | ||
| type: 'unknown_error', | ||
| }; | ||
|
|
||
| // Act | ||
| const result = isGenericError(error); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it('isGenericError_ValidGenericErrorWithParseErrorType_ReturnsTrue', () => { | ||
| // Arrange | ||
| const error: GenericError = { | ||
| error: 'Parsing_error', | ||
| message: 'Error parsing value from session storage', | ||
| type: 'parse_error', | ||
| }; | ||
|
|
||
| // Act | ||
| const result = isGenericError(error); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('failure cases', () => { | ||
| it('isGenericError_NullValue_ReturnsFalse', () => { | ||
| // Arrange | ||
| const value = null; | ||
|
|
||
| // Act | ||
| const result = isGenericError(value); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('isGenericError_UndefinedValue_ReturnsFalse', () => { | ||
| // Arrange | ||
| const value = undefined; | ||
|
|
||
| // Act | ||
| const result = isGenericError(value); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('isGenericError_PrimitiveString_ReturnsFalse', () => { | ||
| // Arrange | ||
| const value = 'error string'; | ||
|
|
||
| // Act | ||
| const result = isGenericError(value); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('isGenericError_PrimitiveNumber_ReturnsFalse', () => { | ||
| // Arrange | ||
| const value = 500; | ||
|
|
||
| // Act | ||
| const result = isGenericError(value); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('isGenericError_EmptyObject_ReturnsFalse', () => { | ||
| // Arrange | ||
| const value = {}; | ||
|
|
||
| // Act | ||
| const result = isGenericError(value); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('isGenericError_ObjectMissingErrorProperty_ReturnsFalse', () => { | ||
| // Arrange | ||
| const value = { | ||
| type: 'unknown_error', | ||
| message: 'Some error message', | ||
| }; | ||
|
|
||
| // Act | ||
| const result = isGenericError(value); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('isGenericError_ObjectMissingTypeProperty_ReturnsFalse', () => { | ||
| // Arrange | ||
| const value = { | ||
| error: 'storage_error', | ||
| message: 'Some error message', | ||
| }; | ||
|
|
||
| // Act | ||
| const result = isGenericError(value); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('isGenericError_ObjectWithNonStringError_ReturnsFalse', () => { | ||
| // Arrange | ||
| const value = { | ||
| error: 123, | ||
| type: 'unknown_error', | ||
| }; | ||
|
|
||
| // Act | ||
| const result = isGenericError(value); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('isGenericError_ObjectWithNonStringType_ReturnsFalse', () => { | ||
| // Arrange | ||
| const value = { | ||
| error: 'storage_error', | ||
| type: 123, | ||
| }; | ||
|
|
||
| // Act | ||
| const result = isGenericError(value); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('isGenericError_ArrayValue_ReturnsFalse', () => { | ||
| // Arrange | ||
| const value = ['error', 'type']; | ||
|
|
||
| // Act | ||
| const result = isGenericError(value); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('isGenericError_ValidDataObject_ReturnsFalse', () => { | ||
| // Arrange | ||
| const value = { | ||
| id: '123', | ||
| name: 'test', | ||
| data: { nested: 'value' }, | ||
| }; | ||
|
|
||
| // Act | ||
| const result = isGenericError(value); | ||
|
|
||
| // Assert | ||
| expect(result).toBe(false); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.