Skip to content

Make StackTrace non-nullable #156

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

Merged
merged 1 commit into from
Dec 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions lib/shelf_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ Future handleRequest(HttpRequest request, Handler handler) async {

if ((response as dynamic) == null) {
// Handle nulls flowing from opt-out code
await _writeResponse(_logError(shelfRequest, 'null response from handler.'),
await _writeResponse(
_logError(
shelfRequest, 'null response from handler.', StackTrace.current),
request.response);
return;
}
Expand Down Expand Up @@ -229,7 +231,7 @@ Future _writeResponse(Response response, HttpResponse httpResponse) {

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

void _logTopLevelError(String message, [StackTrace? stackTrace]) {
var chain = Chain.current();
if (stackTrace != null) {
chain = Chain.forTrace(stackTrace);
}
chain = chain
void _logTopLevelError(String message, StackTrace stackTrace) {
final chain = Chain.forTrace(stackTrace)
.foldFrames((frame) => frame.isCore || frame.package == 'shelf')
.terse;

Expand Down