55*
66*/
77
8- import { error , warning } from "log/mod.ts" ;
8+ import { warning } from "log/mod.ts" ;
99import { existsSync } from "fs/mod.ts" ;
1010import { basename , dirname , join , relative } from "path/mod.ts" ;
1111
12- import { listenAndServe } from "http/mod.ts" ;
13-
1412import { ld } from "lodash/mod.ts" ;
1513import { DOMParser } from "deno_dom/deno-dom-wasm-noinit.ts" ;
1614
@@ -48,7 +46,6 @@ import {
4846import {
4947 httpFileRequestHandler ,
5048 HttpFileRequestOptions ,
51- maybeDisplaySocketError ,
5249} from "../../core/http.ts" ;
5350import { ServeOptions } from "./types.ts" ;
5451import { copyProjectForServe } from "./serve-shared.ts" ;
@@ -256,6 +253,7 @@ export async function serveProject(
256253 ) ;
257254 }
258255 let result : RenderResult | undefined ;
256+ let renderError : Error | undefined ;
259257 if ( inputFile ) {
260258 const renderFlags = { ...flags , quiet : true } ;
261259 // remove 'to' argument to allow the file to be rendered in it's default format
@@ -281,27 +279,28 @@ export async function serveProject(
281279 ) ;
282280 if ( result . error ) {
283281 logError ( result . error ) ;
282+ renderError = result . error ;
284283 }
285284 } catch ( e ) {
286285 logError ( e ) ;
286+ renderError = e ;
287287 }
288288 }
289289
290290 // read the output file
291- const fileContents = Deno . readFileSync ( file ) ;
291+ const fileContents = renderError
292+ ? renderErrorPage ( renderError )
293+ : Deno . readFileSync ( file ) ;
292294
293295 // inject watcher client for html
294- if (
295- isHtmlContent ( file ) && inputFile && result && result . files . length > 0
296- ) {
296+ if ( isHtmlContent ( file ) && inputFile ) {
297297 const projInputFile = join (
298298 project ! . dir ,
299299 relative ( watcher . serveProject ( ) . dir , inputFile ) ,
300300 ) ;
301301 return watcher . injectClient (
302302 fileContents ,
303303 projInputFile ,
304- result . files [ 0 ] . format ,
305304 ) ;
306305 } else {
307306 return fileContents ;
@@ -394,6 +393,11 @@ export async function serveProject(
394393 }
395394}
396395
396+ function renderErrorPage ( e : Error ) {
397+ const content = e . message ;
398+ return new TextEncoder ( ) . encode ( content ) ;
399+ }
400+
397401async function serveFiles (
398402 project : ProjectContext ,
399403) : Promise < { files : string [ ] ; resourceFiles : string [ ] } > {
0 commit comments