Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use macro when setting errors

  • Loading branch information...
commit c18a78bb3f0a8ab0021b00773a0446f44b6525a3 1 parent 49c9a5e
Mirek Rusin mirek authored

Showing 1 changed file with 5 additions and 36 deletions. Show diff stats Hide diff stats

  1. +5 36 YAMLSerialization.m
41 YAMLSerialization.m
@@ -76,24 +76,12 @@ static int YAMLSerializationProcessValue(yaml_document_t *document, id value) {
76 76
77 77 yaml_document_t *document = (yaml_document_t*)malloc( sizeof(yaml_document_t));
78 78 if (!document) {
79   - //YAML_SET_ERROR(kYAMLErrorCodeOutOfMemory, @"Error in yaml_parser_initialize(&parser)", @"Internal error, please let us know about this error");
80   - if (error)
81   - *error = [NSError errorWithDomain: YAMLErrorDomain
82   - code: kYAMLErrorCodeOutOfMemory
83   - userInfo: [NSDictionary dictionaryWithObjectsAndKeys:
84   - @"Couldn't allocate memory", NSLocalizedDescriptionKey,
85   - @"Please try to free memory and retry", NSLocalizedRecoverySuggestionErrorKey,
86   - nil]];
  79 + YAML_SET_ERROR(kYAMLErrorCodeOutOfMemory, @"Couldn't allocate memory", @"Please try to free memory and retry");
87 80 return NULL;
88 81 }
89 82
90 83 if (!yaml_document_initialize(document, NULL, NULL, NULL, 0, 0)) {
91   - *error = [NSError errorWithDomain: YAMLErrorDomain
92   - code: kYAMLErrorInvalidYamlObject
93   - userInfo: [NSDictionary dictionaryWithObjectsAndKeys:
94   - @"Failed to initialize yaml document", NSLocalizedDescriptionKey,
95   - @"Underlying date structure failed to initalize", NSLocalizedRecoverySuggestionErrorKey,
96   - nil]];
  84 + YAML_SET_ERROR(kYAMLErrorInvalidYamlObject, @"Failed to initialize yaml document", @"Underlying data structure failed to initalize");
97 85 free(document);
98 86 return NULL;
99 87 }
@@ -119,12 +107,7 @@ static int YAMLSerializationProcessValue(yaml_document_t *document, id value) {
119 107 }
120 108 else {
121 109 //unsupported root element
122   - *error = [NSError errorWithDomain: YAMLErrorDomain
123   - code: kYAMLErrorInvalidYamlObject
124   - userInfo: [NSDictionary dictionaryWithObjectsAndKeys:
125   - @"Yaml object must be either NSDictionary of NSArray. Scalar roots are pointless.", NSLocalizedDescriptionKey,
126   - @"Send dictionary or array as yaml document root", NSLocalizedRecoverySuggestionErrorKey,
127   - nil]];
  110 + YAML_SET_ERROR(kYAMLErrorInvalidYamlObject, @"Yaml object must be either NSDictionary of NSArray. Scalar roots are pointless.", @"Send dictionary or array as yaml document root");
128 111 free(document);
129 112 return NULL;
130 113 }
@@ -168,16 +151,9 @@ static id YAMLSerializationWithDocument(yaml_document_t *document, YAMLReadOptio
168 151 if (opt & kYAMLReadOptionStringScalars) {
169 152 // Supported
170 153 } else {
171   - if (error)
172   - *error = [NSError errorWithDomain: YAMLErrorDomain
173   - code: kYAMLErrorInvalidOptions
174   - userInfo: [NSDictionary dictionaryWithObjectsAndKeys:
175   - @"Currently kYAMLReadOptionStringScalars is supported", NSLocalizedDescriptionKey,
176   - @"Serialize with kYAMLReadOptionStringScalars option", NSLocalizedRecoverySuggestionErrorKey,
177   - nil]];
  154 + YAML_SET_ERROR(kYAMLErrorInvalidOptions, @"Currently only kYAMLReadOptionStringScalars is supported", @"Serialize with kYAMLReadOptionStringScalars option");
178 155 return nil;
179 156 }
180   -
181 157
182 158 yaml_node_t *node;
183 159 yaml_node_item_t *item;
@@ -187,14 +163,7 @@ static id YAMLSerializationWithDocument(yaml_document_t *document, YAMLReadOptio
187 163
188 164 objects = (id *)malloc(sizeof(id) * (document->nodes.top - document->nodes.start));
189 165 if (!objects) {
190   - //YAML_SET_ERROR(kYAMLErrorCodeOutOfMemory, @"Error in yaml_parser_initialize(&parser)", @"Internal error, please let us know about this error");
191   - if (error)
192   - *error = [NSError errorWithDomain: YAMLErrorDomain
193   - code: kYAMLErrorCodeOutOfMemory
194   - userInfo: [NSDictionary dictionaryWithObjectsAndKeys:
195   - @"Couldn't allocate memory", NSLocalizedDescriptionKey,
196   - @"Please try to free memory and retry", NSLocalizedRecoverySuggestionErrorKey,
197   - nil]];
  166 + YAML_SET_ERROR(kYAMLErrorCodeOutOfMemory, @"Couldn't allocate memory", @"Please try to free memory and retry");
198 167 return nil;
199 168 }
200 169

0 comments on commit c18a78b

Please sign in to comment.
Something went wrong with that request. Please try again.