Repository: ViacomInc/data-point
Pull request #384 (2019-08-21 21:33:54)

fix(data-point): ReducerEntity is now rethrowing error when not handled
<!--
Thanks for your interest in the project. We appreciate bugs filed and PRs submitted!

Please make sure that you are familiar with and follow the Code of Conduct for
this project (found in the CODE_OF_CONDUCT.md file).

Also, please make sure you're familiar with and follow the instructions in the
contributing guidelines (found in the CONTRIBUTING.md file).

Please fill out the information below to expedite the review and (hopefully)
merge of your pull request!

BREAKING CHANGES:

If your PR includes a breaking change, please submit it with a codemod under
data-point-codemods that will help users upgrade their codebase.

Breaking changes without a codemod will not be accepted unless a codemod is not
viable or does not apply to the specific situation.
-->

<!-- What changes are being made? (What feature/bug is being fixed here?) -->
**What**:

Makes sure any error is re-thrown if not handled by the catch reducer

<!-- Why are these changes necessary? -->
**Why**:

ReducerEntity was not throwing error

<!-- 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? -->
- [ ] Added username to **all-contributors** list

<!-- feel free to add additional comments -->

codecov[bot]: # [Codecov](https://codecov.io/gh/ViacomInc/data-point/pull/384?src=pr&el=h1) Report
> Merging [#384](https://codecov.io/gh/ViacomInc/data-point/pull/384?src=pr&el=desc) into [canary](https://codecov.io/gh/ViacomInc/data-point/commit/0d46d7c2042c0c3dde71cea5fd72828806ff0f27?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/384/graphs/tree.svg?width=650&token=LYxItnrx4i&height=150&src=pr)](https://codecov.io/gh/ViacomInc/data-point/pull/384?src=pr&el=tree)

```diff
@@          Coverage Diff          @@
##           canary   #384   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          11     11           
  Lines         226    228    +2     
  Branches       35     35           
=====================================
+ Hits          226    228    +2
```


| [Impacted Files](https://codecov.io/gh/ViacomInc/data-point/pull/384?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [packages/data-point/src/ReducerEntity.js](https://codecov.io/gh/ViacomInc/data-point/pull/384/diff?src=pr&el=tree#diff-cGFja2FnZXMvZGF0YS1wb2ludC9zcmMvUmVkdWNlckVudGl0eS5qcw==) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/ViacomInc/data-point/pull/384?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/384?src=pr&el=footer). Last update [0d46d7c...5c26baf](https://codecov.io/gh/ViacomInc/data-point/pull/384?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/packages/data-point/src/ReducerEntity.js b/packages/data-point/src/ReducerEntity.js
index 1732e79..28f2581 100644
--- a/packages/data-point/src/ReducerEntity.js
+++ b/packages/data-point/src/ReducerEntity.js
@@ -85,11 +85,13 @@ class ReducerEntity extends Reducer {
 
       if (this.catch) {
         acc = acc.set("value", await resolveReducer(acc, this.catch));
+        if (this.outputType) {
+          await resolveReducer(acc, this.outputType);
+        }
+        return acc.value;
       }
 
-      if (this.outputType) {
-        await resolveReducer(acc, this.outputType);
-      }
+      throw error;
     }
 
     return acc.value;


Test patch:
diff --git a/packages/data-point/src/ReducerEntity.test.js b/packages/data-point/src/ReducerEntity.test.js
index d6ddd34..082736a 100644
--- a/packages/data-point/src/ReducerEntity.test.js
+++ b/packages/data-point/src/ReducerEntity.test.js
@@ -130,9 +130,13 @@ describe("ReducerEntity", () => {
 
         const acc = new Accumulator();
 
-        const error = await entity
-          .resolveReducer(acc, mockResolveReducer)
-          .catch(err => err);
+        let error;
+
+        try {
+          await entity.resolveReducer(acc, mockResolveReducer);
+        } catch (err) {
+          error = err;
+        }
 
         expect(error).toMatchInlineSnapshot(`[Error: entityError]`);
         expect(error.reducer).toEqual(entity);