error controller navigation#775
Conversation
Bundle ReportChanges will increase total bundle size by 55.04kB (0.95%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: core/playerAssets Changed:
view changes for bundle: plugins/markdown/coreAssets Changed:
view changes for bundle: plugins/common-expressions/coreAssets Changed:
view changes for bundle: plugins/check-path/coreAssets Changed:
view changes for bundle: plugins/async-node/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/metrics/coreAssets Changed:
view changes for bundle: plugins/reference-assets/coreAssets Changed:
view changes for bundle: plugins/beacon/coreAssets Changed:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## error-controller #775 +/- ##
====================================================
- Coverage 85.84% 85.75% -0.10%
====================================================
Files 508 508
Lines 22892 22992 +100
Branches 2673 2697 +24
====================================================
+ Hits 19652 19717 +65
- Misses 2911 2946 +35
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.
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.
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.
The errorState is optional for both flow and node level. Also for some states like end state, errorState may not be needed
| let errorStateName: string | undefined; | ||
|
|
||
| if (typeof errorStateConfig === "string") { | ||
| errorStateName = errorStateConfig; | ||
| } else { | ||
| errorStateName = | ||
| (errorType && errorStateConfig[errorType]) || errorStateConfig["*"]; | ||
| } |
There was a problem hiding this comment.
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.
Why do we need this function? Couldn't we just use the existing transition function?
There was a problem hiding this comment.
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.
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
| * Type guard to check if a value is a non-null object record. | ||
| * This excludes arrays, null, and other non-object types. | ||
| */ | ||
| export function isRecord(obj: unknown): obj is Record<PropertyKey, unknown> { |
There was a problem hiding this comment.
Huh, surprised this isn't a standard function from ts
|
Looks good in principle, just a couple minor questions we might want to resolve before fully merging it |
core/types/src/index.ts
Outdated
| | NavigationFlowState; | ||
| | NavigationFlowState | ||
| | NavigationFlowTransition | ||
| | Record<string, string>; |
There was a problem hiding this comment.
I think NavigationFlowTransition already covers this case?
* 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?