-
Notifications
You must be signed in to change notification settings - Fork 190
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
Over-released NSError in renderObject:fromContentsOfFile:error: #6
Comments
This issue has been closed thanks to your pull request. Thank you very much! |
Hi, |
Oops. Investigating. |
@pawan1011 I can not reproduce your issue. Here is some code that works fine, for instance: #import <Foundation/Foundation.h>
#import "GRMustache.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSError *error;
id data = @{};
NSString *rendering = [GRMustacheTemplate renderObject:data fromString:@"{{fail" error:&error];
if (!rendering) {
// works fine
NSLog(@"error is %@",[error userInfo]);
}
}
return 0;
} Please attach some minimal code that exhibits this crash, so that we figure out where is your problem. |
NSString *tempStr= [[NSString alloc ]initWithString:@"Replacable String"]; I assumed GRMustache will throw a error for the above code since the Templates do not match. But it did not..!! |
Sure I can. Errors are documented at https://github.com/groue/GRMustache/blob/master/Guides/templates.md :
That means that the only errors you get are parse errors (for unparsable templates), and template not found errors (when loading a template file that does not exist, for instance). Your template, The mismatch you are experiencing is between the GRMustache has absolutely no opinion on keys that should be provided by data. If data provides This is the way GRMustache works: missing keys are not errors. They are just not rendered at all. You may find this behavior annoying. Actually, it is quite useful: check https://github.com/groue/GRMustache/blob/master/Guides/runtime/context_stack.md for the big picture. But let's get back to your problem: since your sample template is quite tiny, it's not very difficult to "fix". However, real-life templates can get huge. It may become tedious to spot this kind of errors. If this is your case, I encourage you reading https://github.com/groue/GRMustache/blob/master/Guides/delegate.md : you may find it useful. Last point: GRMustache returns errors in the conventional Objective-C way ( https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ErrorHandlingCocoa/CreateCustomizeNSError/CreateCustomizeNSError.html). Particularly (emphasis mine):
In your particular case, since I hope things are clearer, now :-) |
Yes.. Now I am able to get 'parse errors ' when the template is of type {{contextPath. |
Please attach some code again. |
Here, I do not have any file by name mustache.xml in that file path specified. But still, Mustache is not throwing any error as expected. |
Look a little closely, with focus and dedication, at the way you invoke GRMustache: you use the Let's go further: since the file does not exist, templateString is Your two options now:
|
Yes groue..I did test and notice that since file does not exist in the path specified ,templateString will be nil. Well, Thanks for clarifying that only [GRMustacheTemplate renderObject:fromContentsOfFile:error:] method will throw an error if the file does not exist in the path specified. |
You're welcome. Happy Mustache! |
I'm having an issue getting the output NSError from
GRMustacheTemplate +renderObject:fromContentsOfFile:error:
. When an error is encountered, theNSError**
I passed in is over-released.The offending code, I believe, is the explicit autorelease pool set up in https://github.com/groue/GRMustache/blob/master/Classes/GRMustacheRendering.m#L201
When an error is encountered, GRMustacheTemplateParser calls
-finishWithError:
which sets its error ivar (retained).The problem is that the template/parser is released when the
NSAutoreleasePool
is drained, thus the error is released. When execution returns back to my code, the error has already been released and if I'll get a violation if I attempt to access it.The text was updated successfully, but these errors were encountered: