Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix,async] exception in async _CancelOnErrorSubscriptionWrapper.onError #855

Merged
merged 9 commits into from
Jan 28, 2025

Conversation

PROGrand
Copy link
Contributor

Patch fixes exception in async (template cast seems to be changed in dart):

Unhandled exception:
type '(Object, StackTrace) => void' is not a subtype of type '(dynamic) => dynamic' in type cast
#0      _CancelOnErrorSubscriptionWrapper.onError.<anonymous closure>.<anonymous closure> (package:async/src/subscription_stream.dart:82:24)
#1      _RootZone.run (dart:async/zone.dart:1670:54)
#2      _FutureListener.handleWhenComplete (dart:async/future_impl.dart:247:18)
#3      Future._propagateToListeners.handleWhenCompleteCallback (dart:async/future_impl.dart:872:39)
#4      Future._propagateToListeners (dart:async/future_impl.dart:928:11)
#5      Future._addListener.<anonymous closure> (dart:async/future_impl.dart:513:9)
#6      _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#7      _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#8      _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#9      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)

@kevmoo
Copy link
Member

kevmoo commented Jan 26, 2025

A test here would be GREAT

Copy link

Package publishing

Package Version Status Publish tag (post-merge)
package:args 2.6.1-wip WIP (no publish necessary)
package:async 2.13.0 ready to publish async-v2.13.0
package:characters 1.4.0 already published at pub.dev
package:collection 1.20.0-wip WIP (no publish necessary)
package:convert 3.1.2 already published at pub.dev
package:crypto 3.0.6 already published at pub.dev
package:fixnum 1.1.1 already published at pub.dev
package:lints 5.1.1 already published at pub.dev
package:logging 1.3.0 already published at pub.dev
package:os_detect 2.0.3 already published at pub.dev
package:path 1.9.2-wip WIP (no publish necessary)
package:platform 3.1.6 already published at pub.dev
package:typed_data 1.4.0 already published at pub.dev

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

Copy link

github-actions bot commented Jan 26, 2025

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
async None 2.12.0 2.13.0 2.12.0 ✔️
Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

Coverage ✔️
File Coverage
pkgs/async/lib/src/result/error.dart 💚 88 % ⬆️ 1 %
pkgs/async/lib/src/subscription_stream.dart 💚 100 % ⬆️ 5 %

This check for test coverage is informational (issues shown here will not fail the PR).

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbols
License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

@PROGrand
Copy link
Contributor Author

@kevmoo

Passing onError as non-inline callback (example) caused type cast errors. Patch covers this case. Now tests for such callbacks (alongside with inline) are added.

Example:

      void f(Object error, StackTrace stackTrace) {
      }

      subscriptionStream.listen((_) {},
          onError: f,
          cancelOnError: true);

@PROGrand PROGrand requested a review from kevmoo January 28, 2025 03:52
@kevmoo
Copy link
Member

kevmoo commented Jan 28, 2025

@lrhn – thoughts on this?

@PROGrand PROGrand requested a review from kevmoo January 28, 2025 08:44
pkgs/async/lib/src/subscription_stream.dart Show resolved Hide resolved
pkgs/async/lib/src/subscription_stream.dart Outdated Show resolved Hide resolved
@PROGrand
Copy link
Contributor Author

@lrhn
Should Error::handle to be changed also?

void handle(Function errorHandler) {
if (errorHandler is ZoneBinaryCallback) {
errorHandler(error, stackTrace);
} else {
(errorHandler as ZoneUnaryCallback)(error);
}
}

@lrhn
Copy link
Member

lrhn commented Jan 28, 2025

That code does look just as wrong. Good catch.
It hasn't been correct since before Dart 2.0 (it actually worked as intended in Dart 1.0).
It's a little scary that nobody has noticed until now. Either nobody types their error handlers (because they rely on inference, which they don't get) or nobody uses the code at all.

@PROGrand
Copy link
Contributor Author

That code does look just as wrong. Good catch. It hasn't been correct since before Dart 2.0 (it actually worked as intended in Dart 1.0). It's a little scary that nobody has noticed until now. Either nobody types their error handlers (because they rely on inference, which they don't get) or nobody uses the code at all.

Ok, i will change this piece too.

@PROGrand PROGrand requested review from lrhn and kevmoo January 28, 2025 19:36
@kevmoo kevmoo merged commit 2458e1a into dart-lang:main Jan 28, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants