Skip to content

fix(blaze): report a rejected attribute promise once - #534

Merged
jankapunkt merged 2 commits into
meteor:release-3.1.0from
dupontbertrand:fix/async-attribute-single-report
Nov 11, 2026
Merged

jankapunkt merged 2 commits into
meteor:release-3.1.0from
dupontbertrand:fix/async-attribute-single-report

Conversation

@dupontbertrand

@dupontbertrand dupontbertrand commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A promise that rejects in an attribute is reported several times. With

Template.example.helpers({
  async asyncHelper() { throw new Error('boom'); },
});
<template name="example"><p data-value="{{asyncHelper}}"></p></template>

the console shows Exception caught in template: Error: boom three times, and a hook on Meteor._debug (Monti APM, for example) records three errors. Every layer of the attribute promise chain in materializer.js reports and rethrows: the attribute value itself (value.then(..., Blaze._reportExceptionAndThrow)), the Promise.all(...) of the attribute set in waitForAllAttributes, then the final then(..., Blaze._reportException) of the attribute updater in materializeTag. Two failing attributes on the same element give five reports, three for the first and two for the second.

The code involved is already on master, so this is not a 3.1 regression.

Change

Only the place where the promise rejects reports it:

  • the Promise.all(...) of waitForAllAttributes lets the rejection through instead of reporting it again;
  • the places where a promise can reject (the attribute value, an element of an array value, a whole attributes object) report it, then rethrow a marker instead of the error;
  • the final then() reports every error that is not that marker, so an error thrown while reading the resolved attributes, for example by a getter on the object a promise resolved to, is still reported once at the end, as before.

The then() helper of materializer.js has no other caller.

Verification

  • New tests in spacebars-tests/async_tests.js, on the existing attribute, attributes and attributes_double templates: a rejected value, a rejected attributes object, a rejected value nested in an attributes object, and two rejected values on the same element. They capture Blaze._reportException and expect one report per rejected promise. On the current code they get three, two, three, and five instead of two.
  • A fifth test, from @nachocodoner's review: an error thrown by a getter while reading the resolved attributes. It reported nothing with the first commit alone and reports getter once with the second.
  • Full Tinytest suite from test-app (Meteor 3.4, same as CI): native DOM backend 425/425, jQuery backend 429/429. No unhandled rejection in the logs.
  • No existing test modified. No version bump, per AGENTS.md.

Changelog

Suggested line for HISTORY.md once the next version heading exists:

* [#NNN](https://github.com/meteor/blaze/pull/NNN) A promise that rejects in an attribute is now reported once instead of once per layer of the attribute promise chain.

A promise that rejects in an attribute was reported by every layer of
the attribute promise chain in materializer.js: where it rejected, again
by the Promise.all of its attribute set, and again by the final then()
of the attribute updater. One failing attribute produced three reports,
two produced five, and tools that hook Meteor._debug counted each of
them as a separate error.

Only the place where the promise rejects reports it now. The enclosing
Promise.all lets the rejection through, and the final then() only keeps
it from going unhandled. Each failing attribute is still reported, once.
The then() helper of materializer.js has no other caller.
@dupontbertrand dupontbertrand mentioned this pull request Nov 7, 2026
31 of 33 tasks
@jankapunkt jankapunkt added this to the 3.1 milestone Nov 11, 2026
Comment thread packages/blaze/materializer.js Resolved
…butes

An error thrown while reading the attributes a promise resolved to, for
example by a getter on the object, rejects the chain from inside the
fulfillment callback of `waitForAllAttributes`, so none of its reporting
handlers sees it. The last `then()` was the only place that reported it,
and the previous commit silenced that `then()`.

Rethrow the rejections that `waitForAllAttributes` reports as a marker,
and let the last `then()` report every other error, so a rejected
promise is still reported once, where it rejects, and an error thrown
while reading the resolved attributes is reported once at the end.
@jankapunkt
jankapunkt merged commit 92a90d3 into meteor:release-3.1.0 Nov 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants