Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Unified Diff: sdk/lib/_internal/pub/lib/src/command/serve.dart

Issue 22878002: Handle missing files more gracefully in pub serve. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/lib/src/utils.dart » ('j') | sdk/lib/_internal/pub/lib/src/utils.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/command/serve.dart
diff --git a/sdk/lib/_internal/pub/lib/src/command/serve.dart b/sdk/lib/_internal/pub/lib/src/command/serve.dart
index ce8db31dd2ea7328041b23ae7a0ac9ad0e4ab491..69d92a1f6085e33b1ca9a41004e0b2438f2dfe4d 100644
--- a/sdk/lib/_internal/pub/lib/src/command/serve.dart
+++ b/sdk/lib/_internal/pub/lib/src/command/serve.dart
@@ -78,14 +78,14 @@ class ServeCommand extends PubCommand {
// are added or modified.
HttpServer.bind("localhost", port).then((server) {
- log.message("Serving ${entrypoint.root.name} "
- "on http://localhost:${server.port}");
-
// Add all of the visible files.
for (var package in provider.packages) {
barback.updateSources(provider.listAssets(package));
}
+ log.message("Serving ${entrypoint.root.name} "
+ "on http://localhost:${server.port}");
+
server.listen((request) {
var id = getIdFromUri(request.uri);
if (id == null) {
@@ -93,14 +93,31 @@ class ServeCommand extends PubCommand {
}
barback.getAssetById(id).then((asset) {
- log.message(
- "$_green${request.method}$_none ${request.uri} -> $asset");
- // TODO(rnystrom): Set content-type based on asset type.
- return request.response.addStream(asset.read()).then((_) {
+ return validateStream(asset.read()).then((stream) {
+ log.message(
+ "$_green${request.method}$_none ${request.uri} -> $asset");
+ // TODO(rnystrom): Set content-type based on asset type.
+ return request.response.addStream(stream).then((_) {
+ request.response.close();
+ });
+ }).catchError((error) {
+ log.error("$_red${request.method}$_none "
+ "${request.uri} -> $error");
+
+ // If we couldn't read the asset, handle the error gracefully.
+ if (error is FileException) {
+ // Assume this means the asset was a file-backed source asset
+ // and we couldn't read it, so treat it like a missing asset.
+ notFound(request, error);
+ return;
+ }
+
+ // Otherwise, it's some internal error.
+ request.response.statusCode = 500;
+ request.response.reasonPhrase = "Internal Error";
+ request.response.write(error);
request.response.close();
});
- // TODO(rnystrom): Serve up a 500 if we get an error reading the
- // asset.
}).catchError((error) {
log.error("$_red${request.method}$_none ${request.uri} -> $error");
if (error is! AssetNotFoundException) {
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/lib/src/utils.dart » ('j') | sdk/lib/_internal/pub/lib/src/utils.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698