Solid · Errors

Errors by path (onError on a selection)

onError on a selected stream is called only for errors at or below its path. In the example the listener on booking receives the two errors inside the booking and the listener on answer receives none, so the code that renders one part of a page handles only the errors of that part.

Schema
z.object({
  booking: z.object({
    id: z.string(),
    seats: z.array(z.string()),
    price_cents: z.number(),
  }),
  answer: z.string(),
  sources: z.array(z.string()),
})
Listeners
stream.onError((error) => errorPaths.stream.push(error.path))
for (const part of ['booking', 'answer', 'sources'])
  stream.select(part).onError((error) => errorPaths[part].push(error.path))
Chunks
[
  '{"booking":{"id":"B-2041","seats":"C4 and C5","price_cents":"76 euros"},',
  '"answer":"Two seats in row C.",',
  '"sources":"the box office"}',
]
Error paths by listener
{
  stream: ['booking.seats', 'booking.price_cents', 'sources'],
  booking: ['booking.seats', 'booking.price_cents'],
  answer: [],
  sources: ['sources'],
}
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.