Repository: ViacomInc/data-point
Pull request #330 (2019-01-17 18:11:48)

feat(data-point): Use _.attempt when calling user defined inspect functions
<!-- What changes are being made? (What feature/bug is being fixed here?) -->
**What**: Use `lodash.attempt` when calling `inspect` functions

<!-- Why are these changes necessary? -->
**Why**: Helps prevent user errors from crashing data-point

<!-- Have you done all of these things?  -->
**Checklist**:
<!-- add "N/A" to the end of each line that's irrelevant to your changes -->
<!-- to check an item, place an "x" in the box like so: "- [x] Documentation" -->
- [ ] Has Breaking changes
- [ ] Documentation
- [x] Tests
- [x] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->

<!-- feel free to add additional comments -->


codecov[bot]: # [Codecov](https://codecov.io/gh/ViacomInc/data-point/pull/330?src=pr&el=h1) Report
> Merging [#330](https://codecov.io/gh/ViacomInc/data-point/pull/330?src=pr&el=desc) into [master](https://codecov.io/gh/ViacomInc/data-point/commit/c090577ff20a3d8af1f89081a8282fafb9be5c6c?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/ViacomInc/data-point/pull/330/graphs/tree.svg?width=650&token=LYxItnrx4i&height=150&src=pr)](https://codecov.io/gh/ViacomInc/data-point/pull/330?src=pr&el=tree)

```diff
@@          Coverage Diff          @@
##           master   #330   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files         139    139           
  Lines        1988   1988           
  Branches      183    183           
=====================================
  Hits         1988   1988
```


| [Impacted Files](https://codecov.io/gh/ViacomInc/data-point/pull/330?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [...a-point/lib/entity-types/entity-request/resolve.js](https://codecov.io/gh/ViacomInc/data-point/pull/330/diff?src=pr&el=tree#diff-cGFja2FnZXMvZGF0YS1wb2ludC9saWIvZW50aXR5LXR5cGVzL2VudGl0eS1yZXF1ZXN0L3Jlc29sdmUuanM=) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/ViacomInc/data-point/pull/330?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/ViacomInc/data-point/pull/330?src=pr&el=footer). Last update [c090577...7b5d222](https://codecov.io/gh/ViacomInc/data-point/pull/330?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/packages/data-point/lib/entity-types/entity-request/resolve.js b/packages/data-point/lib/entity-types/entity-request/resolve.js
index d4815c0..325b7f3 100644
--- a/packages/data-point/lib/entity-types/entity-request/resolve.js
+++ b/packages/data-point/lib/entity-types/entity-request/resolve.js
@@ -118,7 +118,7 @@ function inspect (acc, request) {
     if (request.body) {
       data.body = request.body.toString('utf8')
     }
-    paramInspect(acc, data)
+    _.attempt(paramInspect, acc, data)
     // This promise chain should not be returned,
     // because it is only being used to trigger
     // the paramInspect callback


Test patch:
diff --git a/packages/data-point/lib/entity-types/entity-request/resolve.test.js b/packages/data-point/lib/entity-types/entity-request/resolve.test.js
index 0264f7d..c8598de 100644
--- a/packages/data-point/lib/entity-types/entity-request/resolve.test.js
+++ b/packages/data-point/lib/entity-types/entity-request/resolve.test.js
@@ -381,7 +381,12 @@ describe('inspect', () => {
     )
   })
   test('It should execute params.inspect when rp.then is called', async () => {
-    const acc = createAcc({ inspect: jest.fn() })
+    const acc = createAcc({
+      inspect: jest.fn(() => {
+        // This helps verify that _.attempt is used when calling inspect
+        throw new Error()
+      })
+    })
     const request = createMockRequest({
       statusCode: 200,
       requestType: 'get'
@@ -410,7 +415,12 @@ describe('inspect', () => {
     ])
   })
   test('It should execute params.inspect when rp.catch is called', async () => {
-    const acc = createAcc({ inspect: jest.fn() })
+    const acc = createAcc({
+      inspect: jest.fn(() => {
+        // This helps verify that _.attempt is used when calling inspect
+        throw new Error()
+      })
+    })
     const request = createMockRequest({
       statusCode: 404,
       requestType: 'get'