(value, pattern)
| 18 | * @param {MatchPattern} pattern The pattern to match `value` against |
| 19 | */ |
| 20 | export function check(value, pattern) { |
| 21 | // Record that check got called, if somebody cared. |
| 22 | // |
| 23 | // We use getOrNullIfOutsideFiber so that it's OK to call check() |
| 24 | // from non-Fiber server contexts; the downside is that if you forget to |
| 25 | // bindEnvironment on some random callback in your method/publisher, |
| 26 | // it might not find the argumentChecker and you'll get an error about |
| 27 | // not checking an argument that it looks like you're checking (instead |
| 28 | // of just getting a "Node code must run in a Fiber" error). |
| 29 | const argChecker = currentArgumentChecker.getOrNullIfOutsideFiber(); |
| 30 | if (argChecker) { |
| 31 | argChecker.checking(value); |
| 32 | } |
| 33 | |
| 34 | const result = testSubtree(value, pattern); |
| 35 | if (result) { |
| 36 | const err = new Match.Error(result.message); |
| 37 | if (result.path) { |
| 38 | err.message += ` in field ${result.path}`; |
| 39 | err.path = result.path; |
| 40 | } |
| 41 | |
| 42 | throw err; |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | * @namespace Match |
no test coverage detected
searching dependent graphs…