Nested check and Match.Where


#1

Lately I’ve been trying to refine and refactor out some of my patterns into small utility libraries.

Today I worked on my custom validations and figured I could nest some of them to obtain combined patterns.

But it seems, nesting check/match patterns does not work.

Take this basic example:

var test = 'test';
check(test, Match.Where(function(test){
  check(test,Match.Where(function(test){
    check(test,String)
  }))
}));

//we get:
r {message: "Match error: Failed Match.Where validation", path: "", sanitizedError: r, errorType: "Match.Error", stack: (...)…}

The moment we enter a Match pattern function nested within another Match pattern function, we get this error back. It does not contain a path so it becomes very hard to catch without a debugger.

Has anyone tried such a pattern with success? Can we call this a bug so that I can report it on github? I’ve search github issue but could not find anything related. Or perhaps is this an intended behaviour? Am I doing something wrong?


#2

For future reference please take a look at https://github.com/meteor/meteor/issues/4196

Basically, match expects a boolean return value, therefore enclosing the inner match within a check defeats that purpose.