-
Notifications
You must be signed in to change notification settings - Fork 57
error controller navigation #775
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
base: error-controller
Are you sure you want to change the base?
Conversation
Bundle ReportChanges will increase total bundle size by 28.59kB (0.5%) ⬆️. This is within the configured threshold ✅ Detailed changes
ℹ️ *Bundle size includes cached data from a previous commit Affected Assets, Files, and Routes:view changes for bundle: core/playerAssets Changed:
view changes for bundle: plugins/beacon/coreAssets Changed:
view changes for bundle: plugins/metrics/coreAssets Changed:
view changes for bundle: plugins/reference-assets/coreAssets Changed:
view changes for bundle: plugins/async-node/coreAssets Changed:
view changes for bundle: plugins/common-expressions/coreAssets Changed:
view changes for bundle: plugins/stage-revert-data/coreAssets Changed:
view changes for bundle: plugins/common-types/coreAssets Changed:
view changes for bundle: plugins/check-path/coreAssets Changed:
view changes for bundle: plugins/markdown/coreAssets Changed:
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## error-controller #775 +/- ##
====================================================
+ Coverage 85.84% 85.87% +0.02%
====================================================
Files 508 509 +1
Lines 22892 22980 +88
Branches 2673 2696 +23
====================================================
+ Hits 19652 19734 +82
- Misses 2911 2917 +6
Partials 329 329 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| if (typeof errorState === "object" && errorState !== null) { | ||
| const dict = errorState as Record<string, string>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulling the check into a type assertion function removes the need to cast after checking here. As well, for real type safety you also need to check !Array.isArray(errorState) since arrays are also object types.
export const isRecord = (
obj: unknown
): obj is Record<PropertyKey, unknown> =>
typeof obj === "object" && obj !== null && !Array.isArray(obj);This example has the values of the record as unknown which would require you to type check those too. You could add a generic to pre-determine the record value type to skip that step but it is technically more error-prone:
export const isRecord = <T>(
obj: unknown
): obj is Record<PropertyKey, T> => ...| const nodeErrorStateConfig = currentState?.value.errorState as | ||
| | ErrorStateTransition | ||
| | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we need to type cast here? Do not all navigation states support an errorState?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The errorState is optional for both flow and node level. Also for some states like end state, errorState may not be needed
| errorController.setOptions({ | ||
| model: dataController, | ||
| logger: this.logger, | ||
| flow: flowController, | ||
| fail: flowResultDeferred.reject, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could some of the properties here just be moved to the constructor so you don't need null checks and fallbacks for everything? Seems like only the dataController isn't available when this is constructed.
| let errorStateName: string | undefined; | ||
|
|
||
| if (typeof errorStateConfig === "string") { | ||
| errorStateName = errorStateConfig; | ||
| } else { | ||
| errorStateName = | ||
| (errorType && errorStateConfig[errorType]) || errorStateConfig["*"]; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems pretty similar to the error controller's resolveErrorState. Could we pull that out into a shared util?
| * @param errorType Optional error type for dictionary-based error transition | ||
| * @returns true if navigation succeeded, false if errorState not defined or navigation failed | ||
| */ | ||
| public transitionToErrorState(errorType?: string): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this function? Couldn't we just use the existing transition function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For node level, I still use the existing transition function. This is the flow-level error we don't have transitions map, so I use error type as the key. Do you think it's better to have consistency between flow and node? I can add transitions to flow level.
samples:
flow:
"errorState": {
"network": "NETWORK_ERROR_VIEW",
}
node:
"SHIPPING_VIEW": {
"state_type": "VIEW",
"ref": "shipping-form",
"errorState": "node-error",
"transitions": {
"node-error": "NODE_ERROR_VIEW"
}
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so. Also if we can centralize some of the logic here and in navigateToErrorState and make them more utility oriented I think it might be cleaner long term as that logic needs to evolve
…er-ui/player into error-controller-navigation
When an error occurs in a state, ErrorController tries in order:
Error with no node/flow errorState → flowResultDeferred.reject(error)
detail doc: 4481c71
Change Type (required)
Indicate the type of change your pull request is:
patchminormajorN/ADoes your PR have any documentation updates?