Skip to content

Commit 9cdc1e1

Browse files
committed
fix: add uncaughtException handler to deal with no config error
setup BRANCH env var in travis to fix this: if BRANCH=code then we fail the script, if not we skip the script.
1 parent efcbf81 commit 9cdc1e1

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

.travis.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
os:
2+
- linux
3+
dist: xenial
14
language: node_js
25
node_js:
36
- lts/*
@@ -26,11 +29,11 @@ notifications:
2629
email: false
2730
deploy:
2831
provider: pages
29-
local-dir: dist
30-
target-branch: master
31-
skip-cleanup: true
32-
github-token: $GITHUB_TOKEN # Set in the settings page of your repository, as a secure variable
33-
keep-history: true
32+
local_dir: dist
33+
target_branch: master
34+
cleanup: true
35+
token: $GITHUB_TOKEN # Set in the settings page of your repository, as a secure variable
36+
keep_history: true
3437
fqdn: proto.school
3538
on:
3639
branch: code

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"dependencies": {
6565
"async": "^2.6.1",
6666
"cids": "^0.7.1",
67-
"err-code": "^2.0.0",
67+
"err-code": "^2.0.3",
6868
"googleapis": "^47.0.0",
6969
"highlight.js": "^9.12.0",
7070
"inquirer": "^7.1.0",

scripts/commands/build-data/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44
- Google APIs for events data
55
*/
66

7+
let log = require('npmlog')
8+
9+
const logGroup = 'build:data'
10+
11+
process.on('uncaughtException', (error) => {
12+
// We can't fail if the branch is code, because it could be the cron job
13+
if (error.code === 'NO_CONFIG' && process.env.BRANCH !== 'code') {
14+
log.error(logGroup, 'ERROR NO_CONFIG:', error.message)
15+
log.warn(logGroup, 'Not enough config set. Skipping build-data script...')
16+
process.exit(0)
17+
}
18+
19+
log.error(logGroup, error.code ? `ERROR ${error.code}:` : '', error.message)
20+
process.exit(1)
21+
})
22+
723
const run = require('../../modules/run')
824
const eventsData = require('./events-data')
925
const mailchimp = require('./mailchimp')

scripts/modules/googleapis/auth.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
Create auth object for connecting with the Google APIs.
33
All required information will be ready from env vars.
44
*/
5+
const errorCode = require('err-code')
56

67
const { google } = require('googleapis')
78

89
if (!process.env.GOOGLE_CLIENT_ID) {
9-
throw new Error('No config available. Add a .env file or make all the config available through env variables. Please check the docs at https://github.com/ProtoSchool/protoschool.github.io/tree/code/scripts')
10+
throw errorCode(
11+
new Error('No config available. Add a .env file or make all the config available through env variables. Please check the docs at https://github.com/ProtoSchool/protoschool.github.io/tree/code/scripts'),
12+
'NO_CONFIG'
13+
)
1014
}
1115

1216
const credentials = {

0 commit comments

Comments
 (0)