eduardoboucas / staticman

💪 User-generated content for Git-powered websites
https://staticman.net
MIT License
2.42k stars 541 forks source link

On failure to connect to GitHub, a MISSING_CONFIG_BLOCK error is thrown #328

Open travisdowns opened 4 years ago

travisdowns commented 4 years ago

Let's say your github token is revoked or otherwise wrong. You should get a GITHUB_READING_FILE error or similar. In fact, due to incorrect error handling, you fall into the parsing validation code, which sees a null config block because the object isn't the file contents at all but an error object, and this gets transmuted to MISSING_CONFIG_BLOCK error w/o any useful details.

campus-ai-app commented 4 years ago

Hi, I'm receiving this error and I don't know if it's related to this bug (wrong token) or whether the configuration file is wrong.

I'm using the staticman.sample.yml file renamed to staticman.yml, v2 endpoints, and the github token is set in the config.production.json. The token corresponds to a valid token in an account that has push rights to the github pages repo.

What can I check to understand where is the problem?

My logs in Heroku when I start the app and try to do a post request are the following:

2020-02-29T14:59:17.059115+00:00 app[web.1]: > staticman@3.0.0 prestart /app
2020-02-29T14:59:17.059120+00:00 app[web.1]: > if [ ! -d node_modules ]; then npm install; fi
2020-02-29T14:59:17.059124+00:00 app[web.1]: 
2020-02-29T14:59:17.070471+00:00 app[web.1]: 
2020-02-29T14:59:17.070472+00:00 app[web.1]: > staticman@3.0.0 start /app
2020-02-29T14:59:17.070472+00:00 app[web.1]: > node index.js
2020-02-29T14:59:17.070472+00:00 app[web.1]: 
2020-02-29T14:59:18.123007+00:00 heroku[web.1]: State changed from starting to up
2020-02-29T14:59:18.090345+00:00 app[web.1]: Staticman API running on port 25924
2020-02-29T14:59:59.163691+00:00 heroku[router]: at=info method=POST path="/v2/entry/CampusAI/CampusAI.github.io/master/comments" host=campusai-staticman.herokuapp.com request_id=feec126f-555a-46df-a919-fa16e487f1af fwd="130.229.146.190" dyno=web.1 connect=1ms service=312ms status=500 bytes=495 protocol=https
2020-02-29T15:01:26.017205+00:00 heroku[router]: at=info method=POST path="/v2/entry/CampusAI/CampusAI.github.io/master/comments" host=campusai-staticman.herokuapp.com request_id=a3d31f0a-5c80-45ee-9b92-1c1de7193a72 fwd="130.229.146.190" dyno=web.1 connect=0ms service=226ms status=500 bytes=495 protocol=https
travisdowns commented 4 years ago

In Heroku, I set the GitHub and RSA tokens via Heroku config variables, not via the config file (I use no config file at all).

I don't know if that's the problem though because in principle the config file should work too. There is some logging I think which indicates how the config was read.

I've fixed the error handling in my branch: you'll still get an error but it should tell you what actually went wrong.

campus-ai-app commented 4 years ago

Ok I'm sorry that was my bad: by setting the token in the configuration file GitHub was recognizing it and automatically invalidating it. Setting it in a Heroku variable solved the issue.