Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
fix: better logging context for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sadams committed Nov 20, 2020
1 parent 6da3b0e commit b61912f
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 69 deletions.
96 changes: 48 additions & 48 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
version: 2.1

aliases:
- &dir ~/repo
- &cache_key dependency-cache-{{ checksum "package.json" }}
- &attach_workspace
attach_workspace:
at: *dir
- &dir ~/repo
- &cache_key dependency-cache-{{ checksum "package.json" }}
- &attach_workspace
attach_workspace:
at: *dir

executors:
default:
working_directory: *dir
docker:
- image: circleci/node:14
default:
working_directory: *dir
docker:
- image: circleci/node:14

jobs:
checkout_code:
executor: default
steps:
- checkout
- restore_cache:
key: *cache_key
- run: npm install
- save_cache:
key: *cache_key
paths:
- ./node_modules
- persist_to_workspace:
root: *dir
paths:
- .
checkout_code:
executor: default
steps:
- checkout
- restore_cache:
key: *cache_key
- run: npm install
- save_cache:
key: *cache_key
paths:
- ./node_modules
- persist_to_workspace:
root: *dir
paths:
- .

test:
executor: default
steps:
- *attach_workspace
- run: npm run lint
- run: npm test
test:
executor: default
steps:
- *attach_workspace
- run: npm run lint
- run: npm test

release:
executor: default
steps:
- *attach_workspace
- run: npm run semantic-release
release:
executor: default
steps:
- *attach_workspace
- run: npm run semantic-release

workflows:
build:
jobs:
build:
jobs:
- checkout_code
- test:
requires:
- checkout_code
- test:
requires:
- checkout_code
- release:
context: org-global
requires:
- test
filters:
branches:
only:
- master
- release:
context: org-global
requires:
- test
filters:
branches:
only:
- master
16 changes: 8 additions & 8 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ name: NPM Audit
on: [push]

jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm audit --audit-level=moderate
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm audit --audit-level=moderate
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"bracketSpacing": false,
"semi": true,
"singleQuote": true,
"tabWidth": 4,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": true
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"lint-fix": "npm run lint -- --fix",
"lint-diff": "LIST=`git diff-index --name-only HEAD | grep '.*\\.js$';`; if [ \"$LIST\" ]; then eslint $LIST; fi",
"precommit-msg": "echo 'Running pre-commit checks... (skip using --no-verify)'",
"precommit": "pretty-quick --staged && npm run precommit-msg && npm run lint-diff",
"semantic-release": "semantic-release",
"test": "tap --lines=100 --branches=84 --functions=100"
},
Expand Down Expand Up @@ -48,7 +49,7 @@
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "pretty-quick --staged && npm run precommit-msg && npm run lint-diff"
"pre-commit": "npm run precommit"
}
},
"dependencies": {
Expand Down
19 changes: 11 additions & 8 deletions src/createHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ function createHandler(config) {
if (closed) {
return;
}
logger.debug(
`Waiting for messages ${queueUrl} to handler via longpoll`,
{longPollSeconds, currentRegion, sqsRegion}
);
logger.debug(`Waiting for messages ${queueUrl} to handler via longpoll`, {
longPollSeconds,
currentRegion,
sqsRegion,
});
const params = {
QueueUrl: queueUrl,
MaxNumberOfMessages: 1,
Expand Down Expand Up @@ -97,7 +98,11 @@ function createHandler(config) {
await invokeHandler(handler, message, messageMetadata);
} catch (e) {
success = false;
logger.error('Failure handling message', e);
logger.error(
'Failure handling message',
{messageMetadata, queueUrl},
e
);
}

if (success) {
Expand Down Expand Up @@ -130,9 +135,7 @@ function createHandler(config) {
deregister,
addQueueHandler(queueUrl, handler) {
if (!enabled) {
logger.warn(
`Attempting to add handler for ${queueUrl} when disabled.`
);
logger.warn(`Attempting to add handler for ${queueUrl} when disabled.`);
} else {
pollMessages(queueUrl, handler);
}
Expand Down
4 changes: 1 addition & 3 deletions test/createHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ function nockReceiveMessage(queueUrl, messageObj, times = 1) {
let messageXml = '';
if (messageObj !== null) {
const message =
typeof messageObj === 'string'
? messageObj
: JSON.stringify(messageObj);
typeof messageObj === 'string' ? messageObj : JSON.stringify(messageObj);
const body = JSON.stringify({
Type: 'Notification',
MessageId: '56f45548-d39f-4d04-ab11-5edb91e02c92',
Expand Down

0 comments on commit b61912f

Please # to comment.