Give a more relevant error message for empty src attribute in include #160#174
Merged
Conversation
| if (_.isEmpty(element.attribs.src)) { | ||
| const error = new Error(`Empty src attribute in include in: ${element.attribs[ATTRIB_CWF]}`); | ||
| this._onError(error); | ||
| element.children = cheerio.parseHTML(utils.createErrorElement(error), true); |
Contributor
There was a problem hiding this comment.
Placing the block here may not catch all empty srcs.
For example if i have this
<dynamic-panel src="" />I get this error
path.js:28
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'path', 'string');
^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string
at assertPath (path.js:28:11)
at Object.resolve (path.js:221:7)
at Parser._preprocess (D:\NUS Year 2\SEM2\markbind\markbind\lib\markbind\lib\parser.js:213:23)
at dom.map.d (D:\NUS Year 2\SEM2\markbind\markbind\lib\markbind\lib\parser.js:359:39)
at Array.map (<anonymous>)
at DomHandler.htmlparser.DomHandler [as _callback] (D:\NUS Year 2\SEM2\markbind\markbind\lib\markbind\lib\parser.js:359:25)
at DomHandler._handleCallback.DomHandler.onerror (D:\NUS Year 2\SEM2\markbind\markbind\node_modules\domhandler\index.js:52:8)
at DomHandler.onend (D:\NUS Year 2\SEM2\markbind\markbind\node_modules\domhandler\index.js:46:7)
at Parser.onend (D:\NUS Year 2\SEM2\markbind\markbind\node_modules\htmlparser2\lib\Parser.js:310:32)
at Tokenizer._finish (D:\NUS Year 2\SEM2\markbind\markbind\node_modules\htmlparser2\lib\Tokenizer.js:853:12)
at Tokenizer.end (D:\NUS Year 2\SEM2\markbind\markbind\node_modules\htmlparser2\lib\Tokenizer.js:844:25)
at Parser.end (D:\NUS Year 2\SEM2\markbind\markbind\node_modules\htmlparser2\lib\Parser.js:338:18)
at Parser.parseComplete (D:\NUS Year 2\SEM2\markbind\markbind\node_modules\htmlparser2\lib\Parser.js:330:7)
at fs.readFile (D:\NUS Year 2\SEM2\markbind\markbind\lib\markbind\lib\parser.js:392:16)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:528:3)| this._onError(error); | ||
| const errorElement = cheerio.parseHTML(utils.createErrorElement(error), true)[0]; | ||
| return Object.assign(element, _.pick(errorElement, ['name', 'attribs', 'children'])); | ||
| } |
Contributor
There was a problem hiding this comment.
Since we want to slowly refactor the code base, perhaps we could split it into its own function? Maybe a Parser#createErrorElement#(element)
acjh
reviewed
Mar 26, 2018
| return _.clone(this.missingIncludeSrc); | ||
| }; | ||
|
|
||
| Parser.prototype._createErrorNode = function (element, error) { |
Contributor
There was a problem hiding this comment.
Can this be a function instead of a method since it doesn't use this?
acjh
approved these changes
Mar 29, 2018
Contributor
|
@rachx You can merge this :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #160
If
element.attribs.srcis empty,includeSrcPathwill benullandpath.resolvewill cause the build to crash with a stack trace.