eugenegujing opened a new pull request, #6443:
URL: https://github.com/apache/texera/pull/6443
### What changes were proposed in this PR?
The five type guards in `dashboard/type/type-predicates.ts` checked their
nested payload with `typeof value.<field> === "object"`, which also accepts
null because `typeof null === "object"` in JavaScript, so an entry like
`{workflow: null}` passed `isDashboardWorkflow` and the `DashboardEntry`
constructor then crashed with an unrelated `TypeError: Cannot read properties
of null` while dereferencing the payload, instead of reaching its intentional
`"Unexpected type in DashboardEntry."` error path. The guards also returned the
falsy input itself rather than `false` for null/undefined input, violating
their declared boolean type-guard signatures.
This PR adds an `isNonNullObject` type guard (`typeof x === "object" && x
!== null`) to the shared predicate utility (`common/util/predicate.ts`, next to
`isDefined`) so the correct non-null object check is discoverable and reusable,
uses it in the four object-payload guards, and switches all five guards to
`!!value && ...` so they return strict booleans in every path.
`isDashboardProject`'s `!value.workflow` exclusion is deliberately unchanged: a
null `workflow` field means "no workflow data", so an object with a string
`name` still classifies as a project and no valid entry changes classification.
### Any related issues, documentation, discussions?
Fixes #6439. The buggy behavior was pinned by the five "(current behavior)"
tests added in #6425 (issue #6400), which this PR flips to assert the corrected
behavior.
### How was this PR tested?
Added `predicate.spec.ts` (8 tests) covering `isNonNullObject` and the
previously untested `isDefined`. Updated `type-predicates.spec.ts`: the four
null-payload pins now assert `toBe(false)`, the null/undefined input cases are
tightened from `toBeFalsy()` to `toBe(false)`, and the `isDashboardProject`
null-workflow case keeps asserting `true` with a comment marking it as an
intentional decision; the 5x5 cross-classification matrix and all of its 25
expected values are untouched, confirming that classification of realistic
entries is unaffected. Ran locally via `yarn ng test --watch=false
--include='**/common/util/predicate.spec.ts'
--include='**/dashboard/type/type-predicates.spec.ts'` (61/61 pass), plus the
full frontend suite whose failure set is identical to the unmodified main
baseline (pre-existing, environment-related failures only), and `tsc --noEmit`
with zero errors.
### Was this PR authored or co-authored using generative AI tooling?
Co-authored using Claude Code(Fable 5).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]