Skip to content

Conversation

@wartab
Copy link
Contributor

@wartab wartab commented Aug 22, 2025

Before this commit, it was wrongly assumed that the stream subscription could not be undefined.

Fixes #63341

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #63341

What is the new behavior?

No error

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Please suggest a way to write this test :(

@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Aug 22, 2025
@ngbot ngbot bot added this to the Backlog milestone Aug 22, 2025
Comment on lines 81 to 90
it('should cleanup without error when the stream function threw an error', async () => {
const injector = Injector.create({
providers: [],
parent: TestBed.inject(Injector),
});
const appRef = TestBed.inject(ApplicationRef);
const res = rxResource({
stream: () => {
throw 'oh no';
},
injector,
});
await appRef.whenStable();

// What now? :(
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('should cleanup without error when the stream function threw an error', async () => {
const injector = Injector.create({
providers: [],
parent: TestBed.inject(Injector),
});
const appRef = TestBed.inject(ApplicationRef);
const res = rxResource({
stream: () => {
throw 'oh no';
},
injector,
});
await appRef.whenStable();
// What now? :(
});
it('should cleanup without error when the stream function threw an error', async () => {
const appRef = TestBed.inject(ApplicationRef);
const res = rxResource({
stream: () => {
throw 'oh no';
},
injector: appRef.injector,
});
await appRef.whenStable();
});

This basically throws today, but shouldn't with your fix.

@wartab
Copy link
Contributor Author

wartab commented Aug 22, 2025

From my understanding, this is actually not what happens. Because if you look at the StackBlitz from my issue, the code itself doesn't throw. The resource is created and is in an error state. res exists.

@JeanMeche
Copy link
Member

JeanMeche commented Aug 22, 2025

What I mean is that the test fails because a runtime error is thrown while awaiting.
https://stackblitz.com/edit/ng-jasmine-t5rdmsq9?file=src%2Fmy-tests.spec.ts

With your fix the test should pass without any expectations.

…threw before returning an `Observable`

Before this commit, it was wrongly assumed that the stream subscription could not be `undefined`.

Fixes angular#63341
@wartab wartab force-pushed the fix-rx-resource-cleanup branch from 3b1dfab to 4a1e0cd Compare August 25, 2025 08:58
@wartab wartab marked this pull request as ready for review August 25, 2025 08:59
@JeanMeche JeanMeche added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Aug 28, 2025
@mmalerba
Copy link
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

@mmalerba mmalerba closed this in 9ae9875 Aug 28, 2025
mmalerba pushed a commit that referenced this pull request Aug 28, 2025
…threw before returning an `Observable` (#63342)

Before this commit, it was wrongly assumed that the stream subscription could not be `undefined`.

Fixes #63341

PR Close #63342
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rxResource abort callback throws when stream function threw before returning an Observable

3 participants