Hexo——bug篇

昨天写博客的时候,一套hexo操作行云流水,奈何一个hexo g报错报了几百行,在终端里的错误让人害怕的发抖,先上图为敬。
一个空格引发的bug

显然这些带有具体文件路径和出错位置的error很难直接百度到解决方法,在百度了很久之后,我找到一个貌似跟我的bug相关的关键词: YAMLException

这是一个在yaml文件中的报错。

于是怀着一个科班出身的计算机人的心态,我决定自己读报错改bug。

  • 首先找到加载出错的原因:
    ERROR Theme config load failed.
    这大概是主题配置文件加载失败了???

  • 其次是出错的文件:
    ERROR Process failed: _config.yml
    果然是主题配置文件出错了!

  • 继续找一下出错原因:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
YAMLException: bad indentation of a mapping entry at line 823, column 3:
counter: true
^
at generateError (/Users/jiahaonan/blog/node_modules/js-yaml/lib/js-yaml/loader.js:165:10)
at throwError (/Users/jiahaonan/blog/node_modules/js-yaml/lib/js-yaml/loader.js:171:9)
at readBlockMapping (/Users/jiahaonan/blog/node_modules/js-yaml/lib/js-yaml/loader.js:1080:7)
at composeNode (/Users/jiahaonan/blog/node_modules/js-yaml/lib/js-yaml/loader.js:1332:12)
at readDocument (/Users/jiahaonan/blog/node_modules/js-yaml/lib/js-yaml/loader.js:1492:3)
at loadDocuments (/Users/jiahaonan/blog/node_modules/js-yaml/lib/js-yaml/loader.js:1548:5)
at Object.load (/Users/jiahaonan/blog/node_modules/js-yaml/lib/js-yaml/loader.js:1569:19)
at Hexo.yamlHelper (/Users/jiahaonan/blog/node_modules/hexo/lib/plugins/renderer/yaml.js:7:15)
at Hexo.tryCatcher (/Users/jiahaonan/blog/node_modules/bluebird/js/release/util.js:16:23)
at Hexo.<anonymous> (/Users/jiahaonan/blog/node_modules/bluebird/js/release/method.js:15:34)
at Promise.then.text (/Users/jiahaonan/blog/node_modules/hexo/lib/hexo/render.js:61:21)
at tryCatcher (/Users/jiahaonan/blog/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/jiahaonan/blog/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/Users/jiahaonan/blog/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/Users/jiahaonan/blog/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/Users/jiahaonan/blog/node_modules/bluebird/js/release/promise.js:694:18)
at _drainQueueStep (/Users/jiahaonan/blog/node_modules/bluebird/js/release/async.js:138:12)
at _drainQueue (/Users/jiahaonan/blog/node_modules/bluebird/js/release/async.js:131:9)
at Async._drainQueues (/Users/jiahaonan/blog/node_modules/bluebird/js/release/async.js:147:5)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/jiahaonan/blog/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)

妈耶,一开始看到这些bug我已经准备放弃了,因为这些bug并没有影响我提交博客的相关操作。

但是每次 hexo g 后总跟着几百行报错我看起来很难受啊。

还是继续冷静的分析一下吧。

  • 找到YAMLException的提示位置,第823行。
    Alt text

所以,原来是我多打了一个空格!

  • 好了,冷静地把空格删掉。
    Alt text

  • 重来一遍hexo g,完美运行~
    Alt text

这个案例告诉我们,修改文件的时候不要把空格不当回事儿,不然都是bug劝退。

小手一抖⬇️