-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
feat(config): validate config after load_config #4381
Conversation
89375a1
to
45d58cd
Compare
@jiangtj It can be a part of a roadmap. But so far we just don't need it. |
if (config.url.trim().length <= 0) { | ||
throw new TypeError('Invalid config detected: "url" should not be empty!'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to include undefined
checking here as well (and root
), need to run before 'string' checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That check is inaccurate for undefined
since it's an empty value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@curbengh I have already added an undefined test cases. It seems working properly.
test/scripts/hexo/validate_config.js
Outdated
should.fail(); | ||
} catch (e) { | ||
e.name.should.eql('TypeError'); | ||
e.message.should.eql('Invalid config detected: "url" should be string!'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined
is practically an empty value. If a user accidentally removes the value of url:
or even the key itself, it's clearer to say "url" should not be empty
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although for YAML, undefined
is usually caused by empty value. But Hexo also supports config in json
format (Although most people just won't using json).
Anyway, I will update the error message then.
@curbengh Would you mind have a look at the PR again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (typeof config.url === 'undefined' || config.url === null || config.url.trim().length <= 0) {
throw new TypeError('Invalid config detected: "url" should not be empty!');
}
I prefer the above, but this PR is acceptable.
What does it do?
Continuation fo #4371 and supersedes #4376.
How to test
Screenshots
Pull request tasks