Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breeze error: Illegal construction - use 'or' to combine checks

I met this Breeze error

[Illegal construction - use 'or' to combine checks]

on Chrome when loading the edit page of an entity. When I refresh the page, the error message no longer appears. This error happens randomly, irregularly on my site. I could not reproduce it using a specified scenario, just met it by random.

I see this error message inside Breeze code

if (curContext.prevContext === null) {
    curContext.prevContext = context;
    // just update the prevContext but don't change the curContext.
    return that;
} else if (context.prevContext === null) {
    context.prevContext = that._context;
} else {
    throw new Error("Illegal construction - use 'or' to combine checks");
}

Could you please tell me: based on above block of code, in which cases this error is thrown?

Thanks a lot.

like image 532
zorro-lp Avatar asked Feb 23 '14 15:02

zorro-lp


1 Answers

My team has been having this problem too. It started happening about a month ago, but has really increased in frequency over the past 1-2 weeks. Possibly the recent chrome release to blame.

Here is what I know, all commentary relative to breeze 1.4.1:

-The behavior is intermittent, and seemingly occurs at random. To me, this indicates a timing issue.

-The primary browser generating this error is chrome. We also support firefox and IE and have no concrete evidence that any browser but chrome is throwing this error. Perhaps the recent release of chrome has a different performance profile that exacerbates a pre-existing issue (again, timing?)

-For us, turning off bundling and minification seems to eliminate the problem. I don't believe there is an issue with our minified code (Microsoft Web Optimizations) as everything works on other browsers regardless. This to me again indicates a timing issue.

-Finally, I was just able to reproduce it in my dev environment with the chrome developer tools open. Using a q promise stack, and painfully navigating the minified code I was able to narrow it down to this: At my app start, I call fetchMetadata. Within the fetchMetadata success handler, I make a call to metadataStore.getEntityType('some_entity') and it is within this breeze method that the error is being generated in my scenario. Something with the metadata store isn't consistently initialized or setup at this early stage in the pages app lifecycle.

EDIT: From the comments, this appears to be a chrome 33 bug where null !== null at random times. For unknown reasons, the minifying of the breeze.debug.js file seems to be related (most/all reports of the problem are happening on a minified version of breeze). For me, changing the following code in breeze.debug.js:

} else if (context.prevContext === null) {
    context.prevContext = that._context;
} else {
    throw new Error("Illegal construction - use 'or' to combine checks");
}

to:

} else if (context.prevContext == null) {
    context.prevContext = that._context;
} else {
    throw new Error("Illegal construction - use 'or' to combine checks");
}

(change === to == on first line) seems to have resolved the issue as a workaround. All other aspects of breeze are working fine for me after this change.

One other thing I have noticed is that the minified version of the function has an argument with the same name of the function (t). This still doesn't explain the results of the "Aaarg" test.

   function t(n, t) {
        if (n._context) {
            for (var i = n._context; i.prevContext != null; )
                i = i.prevContext;
            if (i.prevContext === null)
                return i.prevContext = t, n;
            if (t.prevContext == null)
                t.prevContext = n._context;
            else
                throw new Error("Illegal construction - use 'or' to combine checks");
        }
        return b(n, t)
    }
like image 84
mathias999us Avatar answered Oct 27 '22 00:10

mathias999us