From 15965708f2b062ca60086728d9ff3d07d2e8906e Mon Sep 17 00:00:00 2001 From: Mario Kostelac Date: Fri, 22 Mar 2019 19:32:15 +0000 Subject: [PATCH] Make missing parameter error more descriptive While debugging some routing errors on deeply nested routes with many parameters, it became difficult to track what parameters were missing. This collects all missing parameters and adds that to the error message. --- .../transition-intent/named-transition-intent.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/router/transition-intent/named-transition-intent.ts b/lib/router/transition-intent/named-transition-intent.ts index ee7c38be..b7292a0f 100644 --- a/lib/router/transition-intent/named-transition-intent.ts +++ b/lib/router/transition-intent/named-transition-intent.ts @@ -206,6 +206,7 @@ export default class NamedTransitionIntent extends TransitionIn // Soak up all the provided string/numbers let numNames = names.length; + let missingParams = []; while (numNames--) { // Only use old params if the names match with the new handler let oldParams = @@ -222,13 +223,16 @@ export default class NamedTransitionIntent extends TransitionIn if (oldParams.hasOwnProperty(paramName)) { params[paramName] = oldParams[paramName]; } else { - throw new Error( - "You didn't provide enough string/numeric parameters to satisfy all of the dynamic segments for route " + - name - ); + missingParams.push(paramName); } } } + if (missingParams.length > 0) { + throw new Error( + `You didn't provide enough string/numeric parameters to satisfy all of the dynamic segments for route ${name}.` + + ` Missing params: ${missingParams}` + ); + } return new UnresolvedRouteInfoByParam(this.router, name, names, params); }