我是靠谱客的博主 过时豆芽,最近开发中收集的这篇文章主要介绍Hexo在Github中搭建博客系统(6)异常处理异常,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

异常

这里主要收集Hexo在搭建博客的时候出现的异常以及处理方案

在进行启动服务器模拟查看时hexo s –debug出现的启动异常

(1) 无法执行now函数异常

1.1 异常内容

13:51:28.741 FATAL (unknown path) [Line 7, Column 533]
  Error: Unable to call `now`, which is undefined or falsey
Template render error: (unknown path) [Line 7, Column 533]
  Error: Unable to call `now`, which is undefined or falsey
    at Object.exports.prettifyError (/Users/hushuang/hexosite/node_modules/nunjucks/src/lib.js:34:15)
    at /Users/hushuang/hexosite/node_modules/nunjucks/src/environment.js:485:31
    at root [as rootRenderFunc] (eval at <anonymous> (/Users/hushuang/hexosite/node_modules/nunjucks/src/environment.js:564:24), <anonymous>:20:3)
    at Obj.extend.render (/Users/hushuang/hexosite/node_modules/nunjucks/src/environment.js:478:15)
    at Obj.extend.renderString (/Users/hushuang/hexosite/node_modules/nunjucks/src/environment.js:326:21)
    at /Users/hushuang/hexosite/node_modules/hexo/lib/extend/tag.js:66:9
    at Promise._execute (/Users/hushuang/hexosite/node_modules/bluebird/js/release/debuggability.js:272:9)
    at Promise._resolveFromExecutor (/Users/hushuang/hexosite/node_modules/bluebird/js/release/promise.js:475:18)
    at new Promise (/Users/hushuang/hexosite/node_modules/bluebird/js/release/promise.js:77:14)
    at Tag.render (/Users/hushuang/hexosite/node_modules/hexo/lib/extend/tag.js:64:10)
    at Object.tagFilter [as onRenderEnd] (/Users/hushuang/hexosite/node_modules/hexo/lib/hexo/post.js:253:16)
    at /Users/hushuang/hexosite/node_modules/hexo/lib/hexo/render.js:65:19
    at tryCatcher (/Users/hushuang/hexosite/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/hushuang/hexosite/node_modules/bluebird/js/release/promise.js:504:31)
    at Promise._settlePromise (/Users/hushuang/hexosite/node_modules/bluebird/js/release/promise.js:561:18)
    at Promise._settlePromise0 (/Users/hushuang/hexosite/node_modules/bluebird/js/release/promise.js:606:10)
    at Promise._settlePromises (/Users/hushuang/hexosite/node_modules/bluebird/js/release/promise.js:685:18)
    at Async._drainQueue (/Users/hushuang/hexosite/node_modules/bluebird/js/release/async.js:138:16)
    at Async._drainQueues (/Users/hushuang/hexosite/node_modules/bluebird/js/release/async.js:148:10)
    at Immediate.Async.drainQueues (/Users/hushuang/hexosite/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:574:20)
    at tryOnImmediate (timers.js:554:5)

1.2 原因

这类异常一般是文章中使用了now( ), 小括号( )属于特殊字符,在编译文章时将now( )当函数处理了,结果找不到函数,就报错了。

1.3 解决方案

可以参考Markdown语法第(0)章-特殊字符
将now( )的小括号通过&#40; &#41; 进行转换


(2) 意外的标记异常

2.1 异常内容

14:55:15.987 FATAL (unknown path) [Line 119, Column 62]
  unexpected token: }}
Template render error: (unknown path) [Line 119, Column 62]
  unexpected token: }}
    at Object.exports.prettifyError (/Users/hushuang/hexosite/node_modules/nunjucks/src/lib.js:34:15)
    at Obj.extend.render (/Users/hushuang/hexosite/node_modules/nunjucks/src/environment.js:468:27)
    at Obj.extend.renderString (/Users/hushuang/hexosite/node_modules/nunjucks/src/environment.js:326:21)
    at /Users/hushuang/hexosite/node_modules/hexo/lib/extend/tag.js:66:9
    at Promise._execute (/Users/hushuang/hexosite/node_modules/bluebird/js/release/debuggability.js:272:9)
    at Promise._resolveFromExecutor (/Users/hushuang/hexosite/node_modules/bluebird/js/release/promise.js:475:18)
    at new Promise (/Users/hushuang/hexosite/node_modules/bluebird/js/release/promise.js:77:14)
    at Tag.render (/Users/hushuang/hexosite/node_modules/hexo/lib/extend/tag.js:64:10)
    at Object.tagFilter [as onRenderEnd] (/Users/hushuang/hexosite/node_modules/hexo/lib/hexo/post.js:253:16)
    at /Users/hushuang/hexosite/node_modules/hexo/lib/hexo/render.js:65:19
    at tryCatcher (/Users/hushuang/hexosite/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/hushuang/hexosite/node_modules/bluebird/js/release/promise.js:504:31)
    at Promise._settlePromise (/Users/hushuang/hexosite/node_modules/bluebird/js/release/promise.js:561:18)
    at Promise._settlePromise0 (/Users/hushuang/hexosite/node_modules/bluebird/js/release/promise.js:606:10)
    at Promise._settlePromises (/Users/hushuang/hexosite/node_modules/bluebird/js/release/promise.js:685:18)
    at Async._drainQueue (/Users/hushuang/hexosite/node_modules/bluebird/js/release/async.js:138:16)
    at Async._drainQueues (/Users/hushuang/hexosite/node_modules/bluebird/js/release/async.js:148:10)
    at Immediate.Async.drainQueues (/Users/hushuang/hexosite/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:574:20)
    at tryOnImmediate (timers.js:554:5)
    at processImmediate [as _immediateCallback] (timers.js:533:5)

2.2 原因

这类异常一般是文章中使用了大括号 { } 这个特殊字符,且没有转义导致编译不通过

2.3 解决方案

可以参考Markdown语法第(0)章-特殊字符
将 { } 的大括号通过&#123; &#125; 进行转换


(3) 模板渲染错误异常

3.1 异常内容

Template render error: parseSignature: expected comma after expression
        at Error.exports.TemplateError (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/lib.js:51:19)
        at Object.extend.fail (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:64:15)
        at Object.extend.parseSignature (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:1077:22)
        at Object.extend.parsePostfix (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:616:47)
        at Object.extend.parsePrimary (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:933:29)
        at Object.extend.parseUnary (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:882:25)
        at Object.extend.parsePow (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:856:25)
        at Object.extend.parseMod (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:844:25)
        at Object.extend.parseFloorDiv (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:832:25)
        at Object.extend.parseDiv (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:820:25)
        at Object.extend.parseMul (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:808:25)
        at Object.extend.parseSub (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:796:25)
        at Object.extend.parseAdd (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:784:25)
        at Object.extend.parseCompare (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:751:25)
        at Object.extend.parseIn (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:720:23)
        at Object.extend.parseNot (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:716:21)
        at Object.extend.parseAnd (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:698:25)
        at Object.extend.parseOr (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:686:25)
        at Object.extend.parseInlineIf (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:668:25)
        at Object.extend.parseExpression (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:663:25)
        at Object.extend.parseNodes (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:1158:30)
        at Object.extend.parse (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:1173:46)
        at Object.extend.parseUntilBlocks (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:1111:24)
        at NunjucksBlock._parseBody (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/lib/extend/tag.js:111:21)
        at NunjucksBlock.parse (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/lib/extend/tag.js:105:19)
        at Object.extend.parseStatement (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:540:36)
        at Object.extend.parseNodes (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:1151:30)
        at Object.extend.parseAsRoot (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:1177:42)
        at Object.module.exports.parse (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/parser.js:1199:18)
        at Object.module.exports.compile (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/compiler.js:1118:48)
        at Obj.extend._compile (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/environment.js:444:35)
        at Obj.extend.compile (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/environment.js:433:18)
        at null.<anonymous> (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/environment.js:378:22)
        at Object.exports.withPrettyErrors (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/lib.js:24:16)
        at Obj.extend.render (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/environment.js:374:20)
        at Obj.extend.renderString (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/nunjucks/src/environment.js:261:21)
        at /media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/lib/extend/tag.js:56:9
        at tryCatcher (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/bluebird/js/main/util.js:24:31)
        at Promise._resolveFromResolver (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/bluebird/js/main/promise.js:427:31)
        at new Promise (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/bluebird/js/main/promise.js:53:37)
        at Tag.render (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/lib/extend/tag.js:55:10)
        at Object.tagFilter [as onRenderEnd] (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/lib/hexo/post.js:253:16)
        at Promise.then.then.then.output (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/lib/hexo/render.js:55:19)
        at tryCatcher (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/bluebird/js/main/util.js:24:31)
        at Promise._settlePromiseFromHandler (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/bluebird/js/main/promise.js:454:31)
        at Promise._settlePromiseAt (/media/WinE/User/Documents/howiefh.github.io/node_modules/hexo/node_modules/bluebird/js/main/promise.js:530:18)

3.2 原因

这类异常一般是文章中使用了某个特殊字符, 解析时讲表达式中的内容按函数处理了,特殊字符没有转义导致编译不通过,就像下面的内容

参数说明
repoOpenShift 库(Repository)地址
message自定提交信息 (默认为 Site updated: { { now(’YYYY-MM-DD HH:mm:ss’) } })

3.3 解决方案

可以参考Markdown语法特殊字符处理 这章内容
将特殊字符通过转义进行转换
当然,最好的方案是避免写特殊字符


下一节:万网域名解析到Github Pages

最后

以上就是过时豆芽为你收集整理的Hexo在Github中搭建博客系统(6)异常处理异常的全部内容,希望文章能够帮你解决Hexo在Github中搭建博客系统(6)异常处理异常所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部