Skip to content

Commit 2a96fe5

Browse files
authored
Make StackTrace non-nullable (#156)
Use `StackTrace.current` in the one call site without a stack trace, this is slightly better than the previous behavior which took the current stack trace after 2 more levels of unrelated function calls.
1 parent 5a77d25 commit 2a96fe5

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/shelf_io.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ Future handleRequest(HttpRequest request, Handler handler) async {
132132

133133
if ((response as dynamic) == null) {
134134
// Handle nulls flowing from opt-out code
135-
await _writeResponse(_logError(shelfRequest, 'null response from handler.'),
135+
await _writeResponse(
136+
_logError(
137+
shelfRequest, 'null response from handler.', StackTrace.current),
136138
request.response);
137139
return;
138140
}
@@ -229,7 +231,7 @@ Future _writeResponse(Response response, HttpResponse httpResponse) {
229231

230232
// TODO(kevmoo) A developer mode is needed to include error info in response
231233
// TODO(kevmoo) Make error output plugable. stderr, logging, etc
232-
Response _logError(Request request, String message, [StackTrace? stackTrace]) {
234+
Response _logError(Request request, String message, StackTrace stackTrace) {
233235
// Add information about the request itself.
234236
var buffer = StringBuffer();
235237
buffer.write('${request.method} ${request.requestedUri.path}');
@@ -243,12 +245,8 @@ Response _logError(Request request, String message, [StackTrace? stackTrace]) {
243245
return Response.internalServerError();
244246
}
245247

246-
void _logTopLevelError(String message, [StackTrace? stackTrace]) {
247-
var chain = Chain.current();
248-
if (stackTrace != null) {
249-
chain = Chain.forTrace(stackTrace);
250-
}
251-
chain = chain
248+
void _logTopLevelError(String message, StackTrace stackTrace) {
249+
final chain = Chain.forTrace(stackTrace)
252250
.foldFrames((frame) => frame.isCore || frame.package == 'shelf')
253251
.terse;
254252

0 commit comments

Comments
 (0)