API  1.0.0
CPError.j
Go to the documentation of this file.
1 /*
2  * CPError.j
3  * Foundation
4  *
5  * Created by Alexander Ljungberg.
6  * Copyright 2013, SlevenBits Ltd.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 
24 CPCappuccinoErrorDomain = kCFErrorDomainCappuccino;
25 CPCocoaErrorDomain = kCFErrorDomainCappuccino; // compat
26 
27 CPUnderlyingErrorKey = kCFErrorUnderlyingErrorKey;
28 
29 CPLocalizedDescriptionKey = kCFErrorLocalizedDescriptionKey;
30 CPLocalizedFailureReasonErrorKey = kCFErrorLocalizedFailureReasonKey;
31 CPLocalizedRecoverySuggestionErrorKey = kCFErrorLocalizedRecoverySuggestionKey;
32 CPLocalizedRecoveryOptionsErrorKey = @"CPLocalizedRecoveryOptionsErrorKey";
33 CPRecoveryAttempterErrorKey = @"CPRecoveryAttempterErrorKey";
34 CPHelpAnchorErrorKey = @"CPHelpAnchorErrorKey";
35 
36 CPStringEncodingErrorKey = @"CPStringEncodingErrorKey";
37 CPURLErrorKey = kCFErrorURLKey;
38 CPFilePathErrorKey = kCFErrorFilePathKey;
39 
56 @implementation CPError : CPObject
57 {
58  id __doxygen__;
59 }
60 
61 + (id)alloc
62 {
63  var obj = new CFError();
64  obj.isa = [self class];
65 
66  return obj;
67 }
68 
69 
70 + (id)errorWithDomain:(CPString)aDomain code:(CPInteger)aCode userInfo:(CPDictionary)aDict
71 {
72  return [[CPError alloc] initWithDomain:aDomain code:aCode userInfo:aDict];
73 }
74 
75 - (id)initWithDomain:(CPString)aDomain code:(CPInteger)aCode userInfo:(CPDictionary)aDict
76 {
77  var result = new CFError(aDomain, aCode, aDict);
78  result.isa = [self class];
79  return result;
80 }
81 
82 - (CPInteger)code
83 {
84  return self.code();
85 }
86 
87 - (CPString)userInfo
88 {
89  return self.userInfo();
90 }
91 
92 - (CPString)domain
93 {
94  return self.domain();
95 }
96 
102 - (CPString)localizedDescription
103 {
104  return self.description();
105 }
106 
107 - (CPString)localizedFailureReason
108 {
109  return self.failureReason();
110 }
111 
112 - (CPArray)localizedRecoveryOptions
113 {
114  var userInfo = self.userInfo(),
115  recoveryOptions = userInfo.valueForKey(CPLocalizedRecoveryOptionsErrorKey);
116 
117  return recoveryOptions;
118 }
119 
120 - (CPString)localizedRecoverySuggestion
121 {
122  return self.recoverySuggestion();
123 }
124 
125 - (id)recoveryAttempter
126 {
127  var userInfo = self.userInfo(),
128  recoveryAttempter = userInfo.valueForKey(CPRecoveryAttempterErrorKey);
129 
130  return recoveryAttempter;
131 }
132 
134 {
135  return [CPString stringWithFormat:@"Error Domain=%@ Code=%d \"%@\" UserInfo=%@", self.domain(), self.code(), self.description(), self.userInfo()];
136 }
137 
138 @end
139 
140 var CPErrorCodeKey = @"CPErrorCodeKey",
141  CPErrorDomainKey = @"CPErrorDomainKey",
142  CPErrorUserInfoKey = @"CPErrorUserInfoKey";
143 
144 @implementation CPError (CPCoding)
145 
146 - (id)initWithCoder:(CPCoder)aCoder
147 {
148  var code = [aCoder decodeIntForKey:CPErrorCodeKey],
149  domain = [aCoder decodeObjectForKey:CPErrorDomainKey],
150  userInfo = [aCoder decodeObjectForKey:CPErrorUserInfoKey];
151 
152  return [self initWithDomain:domain
153  code:code
154  userInfo:userInfo];
155 }
156 
157 - (void)encodeWithCoder:(CPCoder)aCoder
158 {
159  [aCoder encodeObject:self.domain() forKey:CPErrorDomainKey];
160  [aCoder encodeObject:self.code() forKey:CPErrorCodeKey];
161  [aCoder encodeObject:self.userInfo() forKey:CPErrorUserInfoKey];
162 }
163 
164 @end
165 
166 CFError.prototype.isa = CPError;
167 
id initWithDomain:code:userInfo:(CPString aDomain, [code] CPInteger aCode, [userInfo] CPDictionary aDict)
Definition: CPError.j:75
CPRecoveryAttempterErrorKey
Definition: CPError.j:33
CPCocoaErrorDomain
Definition: CPError.j:25
CPLocalizedFailureReasonErrorKey
Definition: CPError.j:30
var CPErrorUserInfoKey
Definition: CPError.j:142
CPFilePathErrorKey
Definition: CPError.j:38
A mutable key-value pair collection.
Definition: CPDictionary.h:2
CPHelpAnchorErrorKey
Definition: CPError.j:34
var CPErrorDomainKey
Definition: CPError.j:141
CPStringEncodingErrorKey
Definition: CPError.j:36
An immutable string (collection of characters).
Definition: CPString.h:2
var CPErrorCodeKey
Definition: CPError.j:140
CPLocalizedRecoverySuggestionErrorKey
Definition: CPError.j:31
CPCappuccinoErrorDomain
Definition: CPError.j:24
Used for encapsulating, presenting, and recovery from errors.
Definition: CPError.h:2
Defines methods for use when archiving & restoring (enc/decoding).
Definition: CPCoder.h:2
CPLocalizedDescriptionKey
Definition: CPError.j:29
CPURLErrorKey
Definition: CPError.j:37
CPString description()
Definition: CPString.j:178
Class class()
Definition: CPObject.j:179
id alloc()
Definition: CPError.j:61
CPUnderlyingErrorKey
Definition: CPError.j:27
CPLocalizedRecoveryOptionsErrorKey
Definition: CPError.j:32
id stringWithFormat:(CPString format, [,] ...)
Definition: CPString.j:166
FrameUpdater prototype description