weixin_40007189
weixin_40007189
2020-12-30 10:56

Error on writing unavailable path in $importContent is not understandable.

Describe the bug Hi, so like we care about what works, in static-site-generators we will also have to care about what doesn't work. And when something doesn't work, there should be a proper error message that mentions why it is not working.

To Reproduce In any .abell project, go to [$path]/index.abell and write $importContent(undefined + '/index.md').

This will throw an error which is completely not understandable to users.

Expected behavior It is supposed to show a better message that explains what is need to be changed.

Additional context

We can add try catch around markdown reading in importAndRender function in src/utils/build-utils.js

该提问来源于开源项目:abelljs/abell

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

13条回答

  • weixin_39894914 weixin_39894914 4月前

    s is it good for you or I should change something ?

    点赞 评论 复制链接分享
  • weixin_40007189 weixin_40007189 4月前

    yes looks great!

    点赞 评论 复制链接分享
  • weixin_40007189 weixin_40007189 4月前

    Oh it is supposed to be error in $importContent

    点赞 评论 复制链接分享
  • weixin_39894914 weixin_39894914 4月前

    oh yeah I'll change it and send a PR

    点赞 评论 复制链接分享
  • weixin_40007189 weixin_40007189 4月前

    Resolved in #48 Thanks!

    点赞 评论 复制链接分享
  • weixin_39894914 weixin_39894914 4月前

    Hey, can you guide a little bit and I will take this issue ?

    点赞 评论 复制链接分享
  • weixin_40007189 weixin_40007189 4月前

    Hi, so if we do a normal setup

    sh
    npx create-abell-app my-blog
    

    And in that if you go to my-blog/theme/[$path]/index.abell, You will find a line {{ $importContent(meta.$path + '/index.md') }}

    If we build this, it will be built properly but for some reason, lets say meta.$path is undefined or someone writes meta.path instead of meta.$path, in that case it throws an error.

    This error does not exactly tell what is wrong, rather it tries to read from undefined/index.md and the read fails.

    Instead of this not understandable error, we want an error like

    
    Error in {{ $importContent() }} 
    at [$path]/index.abell
    
    content does not exist
    
    点赞 评论 复制链接分享
  • weixin_40007189 weixin_40007189 4月前

    https://github.com/abelljs/abell/blob/main/src/utils/build-utils.js#L169

    This is the line that imports content

    点赞 评论 复制链接分享
  • weixin_39894914 weixin_39894914 4月前

    so I just add a try catch method and add the custom error message ?

    点赞 评论 复制链接分享
  • weixin_40007189 weixin_40007189 4月前

    yes and if you feel like adding some more information that can help in finding where the problem is, you can go ahead and do that

    点赞 评论 复制链接分享
  • weixin_39894914 weixin_39894914 4月前

    I finished it but how can I test if it work ?

    点赞 评论 复制链接分享
  • weixin_39894914 weixin_39894914 4月前

    here is how I did it, I check if the contentPath is not undefined if it's undefined I return a error

    点赞 评论 复制链接分享
  • weixin_40007189 weixin_40007189 4月前
    • Do npm link, This will make abell command accessible to you from command line,
    • In examples/main/theme/[$path]/index.abell, you can change the importContent path to $importContent(undefined + '/index.md')
    • abell build inside examples/main to build the main project and check what it outputs ``
    点赞 评论 复制链接分享

相关推荐