From b61912fc7b7a0a3f8ba4b0db1fddfc953930b8e4 Mon Sep 17 00:00:00 2001 From: Sam Adams Date: Fri, 20 Nov 2020 16:20:30 +0000 Subject: [PATCH] fix: better logging context for errors --- .circleci/config.yml | 96 ++++++++++++++++++------------------- .github/workflows/audit.yml | 16 +++---- .prettierrc | 2 +- package.json | 3 +- src/createHandler.js | 19 ++++---- test/createHandler.test.js | 4 +- 6 files changed, 71 insertions(+), 69 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index edb1b5f..1a17bba 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 9b7d517..53488ba 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -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 diff --git a/.prettierrc b/.prettierrc index d0028cf..385e786 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,7 +2,7 @@ "bracketSpacing": false, "semi": true, "singleQuote": true, - "tabWidth": 4, + "tabWidth": 2, "trailingComma": "es5", "useTabs": true } diff --git a/package.json b/package.json index 5dba7ce..8971b3e 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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": { diff --git a/src/createHandler.js b/src/createHandler.js index 644b787..2ab8dfa 100644 --- a/src/createHandler.js +++ b/src/createHandler.js @@ -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, @@ -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) { @@ -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); } diff --git a/test/createHandler.test.js b/test/createHandler.test.js index 5698032..d7d09df 100644 --- a/test/createHandler.test.js +++ b/test/createHandler.test.js @@ -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',