Skip to content

Commit

Permalink
Improve error message when autoloading invalid view engine
Browse files Browse the repository at this point in the history
fixes #3403
  • Loading branch information
dougwilson committed Sep 26, 2017
1 parent 73114b6 commit ce1f847
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased
==========

* Improve error message when autoloading invalid view engine

4.15.5 / 2017-09-24
===================

Expand Down
10 changes: 9 additions & 1 deletion lib/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ function View(name, options) {
// load engine
var mod = this.ext.substr(1)
debug('require "%s"', mod)
opts.engines[this.ext] = require(mod).__express

// default engine export
var fn = require(mod).__express

if (typeof fn !== 'function') {
throw new Error('Module "' + mod + '" does not provide a view engine.')
}

opts.engines[this.ext] = fn
}

// store loaded engine
Expand Down
Empty file added test/fixtures/broken.send
Empty file.
14 changes: 14 additions & 0 deletions test/res.render.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ describe('res', function(){
.expect('<p>tobi</p>', done);
})

it('should error without "view engine" set and file extension to a non-engine module', function (done) {
var app = createApp()

app.locals.user = { name: 'tobi' }

app.use(function (req, res) {
res.render(path.join(__dirname, 'fixtures', 'broken.send'))
})

request(app)
.get('/')
.expect(500, /does not provide a view engine/, done)
})

it('should error without "view engine" set and no file extension', function (done) {
var app = createApp();

Expand Down

0 comments on commit ce1f847

Please sign in to comment.