Skip to content

Signal Forms: validateStandardSchema throws a TypeError for an issue whose path runs through a key the model lacks #71128

Description

@Cynthion

Which @angular/* package(s) are the source of the bug?

forms

Is this a regression?

No

Description

standardIssueToFormTreeError() walks an issue's path with target = target[pathKey]. For an unknown last key, target ends up undefined and the error falls back to the field the schema validates, which is fine. For an unknown key anywhere before the last one, the next step reads a property of undefined, and reading errors() throws.

import { signal } from '@angular/core';
import { form, validateStandardSchema } from '@angular/forms/signals';
import type { StandardSchemaV1 } from '@standard-schema/spec';

function reportsOn(path: PropertyKey[]): StandardSchemaV1<{ name: string }> {
  return {
    '~standard': {
      version: 1,
      vendor: 'repro',
      validate: () => ({ issues: [{ message: 'Wrong.', path }] }),
    },
  };
}

// In an injection context:
const lastKey = form(signal({ name: '' }), (p) => validateStandardSchema(p, reportsOn(['ghost'])));
lastKey().errors(); // one error, 'Wrong.', on the root

const middleKey = form(signal({ name: '' }), (p) => validateStandardSchema(p, reportsOn(['ghost', 'name'])));
middleKey().errors(); // TypeError: Cannot read properties of undefined (reading 'name')

A Standard Schema can easily report outside the bound model: a schema written for a wider object, a refinement with a computed path, a Vest test whose name is not a model key. Today one such issue makes errors() throw.

Expected: the same fallback as for an unknown last key. target = target?.[pathKey] in that loop would give it.

Minimal reproduction

The snippet above.

Exception or error

TypeError: Cannot read properties of undefined (reading 'name')

Environment

Angular CLI 22.2.0, Angular 22.2.0, Node.js 26.7.0, darwin arm64. standardIssueToFormTreeError() is the same in 22.2.1, 22.3.0-next.0 and on main.

Anything else?

No.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: formsgemini-triagedLabel noting that an issue has been triaged by gemini

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions