-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Exception Reporting #291
Comments
Actually that templateFunc.name was always set to "bind" so instead we decided to update wrapHelper to take a name parameter which is uses instead of "template helper". Then when calling wrapHelper we just pass
This works nicely so far. |
Do you have a PR for this or just a fork of Blaze? Can you show your code? |
Hi @jamesgibson14. I just monkeypatched it. It would be easy to make a PR as it's a tiny change. Here's our code:
|
Thank you, I was looking at this same Blaze code and wondering if I could
patch it. I will try your code out. It would be nice to get it in as a PR.
…On Mon, Mar 1, 2021 at 4:03 AM lynchem ***@***.***> wrote:
Hi @jamesgibson14 <https://github.com/jamesgibson14>. I just
monkeypatched it. It would be easy to make a PR as it's a tiny change.
Here's our code:
// If `x` is a function, binds the value of `this` for that function
// to the current data context.
function bindDataContext(x) {
if (typeof x === "function") {
return function() {
let data = Blaze.getData();
if (data === null) {
data = {};
}
return x.apply(data, arguments);
};
}
return x;
}
function wrapHelper(f, templateFunc, name) {
if (typeof f !== "function") {
return f;
}
return function() {
let self = this;
let args = arguments;
return Blaze.Template._withTemplateInstanceFunc(templateFunc, function() {
return Blaze._wrapCatchingExceptions(f, name).apply(self, args);
});
};
}
Blaze._wrapCatchingExceptions = function(f, where) {
if (typeof f !== "function") {
return f;
}
return function() {
try {
return f.apply(this, arguments);
} catch (e) {
if (ObitEnvironment.isTesting()) {
throw e;
} else {
Blaze._reportException(e, `Exception in ${where}:`);
}
}
};
};
Blaze._getTemplateHelper = function(template, name, tmplInstanceFunc) {
if (template.__helpers.has(name)) {
let helper = template.__helpers.get(name);
if (helper === Blaze._OLDSTYLE_HELPER) {
throw new Meteor.Error("not-suported", "We removed support for old style templates");
} else if (helper !== null) {
return wrapHelper(
bindDataContext(helper),
tmplInstanceFunc,
`${template.viewName} ${name}`
);
} else {
return null;
}
}
return null;
};
Blaze._getGlobalHelper = function(name, templateInstance) {
if (Blaze._globalHelpers[name] !== null) {
return wrapHelper(
bindDataContext(Blaze._globalHelpers[name]),
templateInstance,
`global helper ${name}`
);
}
return null;
};
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#291 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFY6KQQUFWW3OKOGZPUJVDTBNYBRANCNFSM4G4DRQLQ>
.
|
I'm closing this issue because it's too old. If you think this issue is still relevant please open a new one. Why? We need to pay attention to all the open items so we should keep opened only items where people are involved. |
@filipenevola - I can understand bugs quickly becoming irrelevant on actively developed codebases but this is hardly the case here. Here's the last two releases. v2.3.4, 2019-Dec-13 There's also been a small bit of discussion of late too. This issue in particular is a really easy win for any blaze user and saved us a few hours of debugging for sure. |
This is not the case here, I just closed all the old items without comments/activity. We can re-open or open new issues for the same problem. As I saw in your original comment that you are willing to make a PR, please go ahead @lynchem |
I just wanted to post here that I tried out @lynchem's "monkey patch" and it works great. |
@StorytellerCZ should we consider this for 3.0 ? |
Yes, that would be a great addition. PRs welcomed! |
Currently in Kadira we get lots of exceptions that look like this:
[client] Exception in tempalte helper:
As there is no more detail they all get grouped together which can be painful to wade through.
One simple update we could make in Blaze is to pass the name of the helper function to _wrapCatchingException (in lookup.js) so
Would be instead something like
It would be even better if we passed the actual template name into wrapHelper and then we could report that too meaning a unique grouping by template name and helper in Kadira or whatever other error handling program someone is using.
I'm happy to make the PR if whoever monitors this agrees 😃
The text was updated successfully, but these errors were encountered: