-
Notifications
You must be signed in to change notification settings - Fork 847
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
Error messages are hard to debug from Express #376
Comments
The second problem I think is in the Express' implementation and can't be fixed in EJS. I think we could do something in EJS to help with the first problem and provide more context about the error. If the template is compiled with a filename option, we could output that to get an error message like this which would be useful information to go on:
I opened up a PR with a sample of this change in #377 |
at lib>ejs.js ==> 709 line, 修改成这样就可以在tag出错时明确知道位置在哪里。 let errorIndex = index, prevStep = 0, prevMax = 0, nextStep = 0, nextMax = 0, errorPrevStr = '', errorNextStr = ''
while (prevStep > -2 && prevMax < 50) {
const stepIndex = errorIndex - prevMax -1
errorPrevStr = matches[stepIndex] + errorPrevStr;
if (matches[stepIndex] === '\n') {
prevStep--
}
prevMax++
}
while (nextStep < 2 && nextMax < 2) {
const stepIndex = errorIndex + nextMax + 1
errorNextStr = matches[stepIndex] + errorNextStr;
if (matches[stepIndex] === '\n') {
nextStep++
}
nextMax ++
}
errorPrevStr = opts.filename + '\n' + errorPrevStr
throw new Error(errorPrevStr + '\n'+ 'Could not find matching close tag for "' + line + '\n' + errorNextStr + '".'); |
In the context of Express, say I create a template that is missing an EJS closing tag as sometimes will happen:
In
views/users/index.ejs
:I get the following error:
This problem is hard to debug:
The text was updated successfully, but these errors were encountered: