@@ -8,6 +8,7 @@ import 'package:async/async.dart' as async;
8
8
import 'package:charcode/ascii.dart' ;
9
9
import 'package:meta/meta.dart' ;
10
10
import 'package:pool/pool.dart' as pool;
11
+ import 'package:stack_trace/stack_trace.dart' ;
11
12
import 'package:stream_channel/stream_channel.dart' ;
12
13
13
14
import '../../postgres.dart' ;
@@ -183,6 +184,7 @@ abstract class _PgSessionBase implements Session {
183
184
}
184
185
185
186
Future <_PreparedStatement > _prepare (Object query) async {
187
+ final trace = Trace .current ();
186
188
final conn = _connection;
187
189
final name = 's/${conn ._statementCounter ++}' ;
188
190
final description = InternalQueryDescription .wrap (
@@ -196,7 +198,7 @@ abstract class _PgSessionBase implements Session {
196
198
typeOids: description.parameterTypes? .map ((e) => e? .oid).toList (),
197
199
));
198
200
199
- return _PreparedStatement (description, name, this );
201
+ return _PreparedStatement (description, name, this , trace );
200
202
}
201
203
}
202
204
@@ -652,7 +654,9 @@ class _PreparedStatement extends Statement {
652
654
/// See more in https://github.com/isoos/postgresql-dart/issues/390
653
655
Queue <String >? _portalsToClose;
654
656
655
- _PreparedStatement (this ._description, this ._name, this ._session);
657
+ final Trace _trace;
658
+
659
+ _PreparedStatement (this ._description, this ._name, this ._session, this ._trace);
656
660
657
661
@override
658
662
ResultStream bind (Object ? parameters) {
@@ -746,14 +750,16 @@ class _PgResultStreamSubscription
746
750
PgConnectionImplementation get connection => session._connection;
747
751
748
752
late final _portalName = 'p/${connection ._portalCounter ++}' ;
749
- final StackTrace _trace;
753
+ final Trace ? _parentTrace;
754
+ final Trace _callerTrace;
750
755
751
756
_PgResultStreamSubscription (
752
757
_BoundStatement statement, this ._controller, this ._source)
753
758
: session = statement.statement._session,
754
759
ignoreRows = false ,
755
760
_boundStatement = statement,
756
- _trace = StackTrace .current {
761
+ _parentTrace = statement.statement._trace,
762
+ _callerTrace = Trace .current () {
757
763
_scheduleStatement (() async {
758
764
connection._pending = this ;
759
765
@@ -791,7 +797,8 @@ class _PgResultStreamSubscription
791
797
this ._source,
792
798
this .ignoreRows, {
793
799
void Function ()? cleanup,
794
- }) : _trace = StackTrace .current {
800
+ }) : _parentTrace = null ,
801
+ _callerTrace = Trace .current () {
795
802
_scheduleStatement (() async {
796
803
connection._pending = this ;
797
804
@@ -834,17 +841,23 @@ class _PgResultStreamSubscription
834
841
await _controller.close ();
835
842
}
836
843
844
+ StackTrace _trace () => Chain ([
845
+ Trace .current (1 ),
846
+ _callerTrace,
847
+ if (_parentTrace != null ) _parentTrace! ,
848
+ ]);
849
+
837
850
@override
838
851
void handleConnectionClosed (PgException ? dueToException) {
839
852
if (dueToException != null ) {
840
- _controller.addError (dueToException, _trace);
853
+ _controller.addError (dueToException, _trace () );
841
854
}
842
855
_completeQuery ();
843
856
}
844
857
845
858
@override
846
859
void handleError (PgException exception) {
847
- _controller.addError (exception, _trace);
860
+ _controller.addError (exception, _trace () );
848
861
}
849
862
850
863
@override
0 commit comments