Vuo  2.3.2
VuoOsStatus.c
Go to the documentation of this file.
1 
10 #include "VuoOsStatus.h"
11 
12 #include "module.h"
13 
14 #include <CoreServices/CoreServices.h>
15 #include <CoreVideo/CVReturn.h>
16 #include <CoreMediaIO/CMIOHardware.h>
17 
18 #ifdef VUO_COMPILER
20  "title" : "VuoOsStatus",
21  "dependencies" : [
22  "CoreFoundation.framework"
23  ]
24  });
25 #endif
26 
32 char *VuoOsStatus_getText(int32_t error)
33 {
34  if (error == 0)
35  return strdup("(no error)");
36  else if (error == bdNamErr)
37  return strdup("Bad file name");
38  else if (error == fnfErr)
39  return strdup("File not found");
40 
41  // LSInfo.h
42  else if (error == kLSAppInTrashErr) return strdup("The app cannot be run when inside a Trash folder");
43  else if (error == kLSExecutableIncorrectFormat) return strdup("No compatible executable was found");
44  else if (error == kLSAttributeNotFoundErr) return strdup("An item attribute value could not be found with the specified name");
45  else if (error == kLSAttributeNotSettableErr) return strdup("The attribute is not settable");
46  else if (error == kLSIncompatibleApplicationVersionErr) return strdup("The app is incompatible with the current OS");
47  else if (error == kLSNoRosettaEnvironmentErr) return strdup("The Rosetta environment was required not available");
48  else if (error == -10666 /*kLSGarbageCollectionUnsupportedErr*/) return strdup("Objective-C garbage collection is no longer supported");
49  else if (error == kLSUnknownErr) return strdup("Unexpected internal error");
50  else if (error == kLSNotAnApplicationErr) return strdup("Item needs to be an application, but is not");
51  else if (error == kLSNotInitializedErr) return strdup("Not initialized");
52  else if (error == kLSDataUnavailableErr) return strdup("Data unavailable (e.g., no kind string)");
53  else if (error == kLSApplicationNotFoundErr) return strdup("Application not found (e.g., no application claims the file)");
54  else if (error == kLSUnknownTypeErr) return strdup("Don't know anything about the type of the item");
55  else if (error == kLSDataTooOldErr) return strdup("Data too old");
56  else if (error == kLSDataErr) return strdup("Data error");
57  else if (error == kLSLaunchInProgressErr) return strdup("Attempted to launch an already launching application");
58  else if (error == kLSNotRegisteredErr) return strdup("Not registered");
59  else if (error == kLSAppDoesNotClaimTypeErr) return strdup("One or more documents are of types (and/or one or more URLs are of schemes) not supported by the target application");
60  else if (error == kLSAppDoesNotSupportSchemeWarning) return strdup("The app does not support this scheme");
61  else if (error == kLSServerCommunicationErr) return strdup("The server process (registration and recent items) is not available");
62  else if (error == kLSCannotSetInfoErr) return strdup("The extension visibility on this item cannot be changed");
63  else if (error == kLSNoRegistrationInfoErr) return strdup("The item contains no registration info");
64  else if (error == kLSIncompatibleSystemVersionErr) return strdup("The app cannot run on the current OS version");
65  else if (error == kLSNoLaunchPermissionErr) return strdup("User doesn't have permission to launch the app (managed networks)");
66  else if (error == kLSNoExecutableErr) return strdup("The executable is missing");
67  else if (error == kLSNoClassicEnvironmentErr) return strdup("The Classic environment was required but is not available");
68  else if (error == kLSMultipleSessionsNotSupportedErr) return strdup("The app cannot run simultaneously in two different sessions");
69 
70  // CVReturn.h
71  else if (error == kCVReturnInvalidArgument) return strdup("At least one of the arguments passed in is not valid. Either out of range or the wrong type.");
72  else if (error == kCVReturnAllocationFailed) return strdup("The allocation for a buffer or buffer pool failed. Most likely because of lack of resources.");
73  else if (error == -6663 /*kCVReturnUnsupported*/) return strdup("Unsupported.");
74  else if (error == kCVReturnInvalidDisplay) return strdup("A CVDisplayLink cannot be created for the given DisplayRef.");
75  else if (error == kCVReturnDisplayLinkAlreadyRunning) return strdup("The CVDisplayLink is already started and running.");
76  else if (error == kCVReturnDisplayLinkNotRunning) return strdup("The CVDisplayLink has not been started.");
77  else if (error == kCVReturnDisplayLinkCallbacksNotSet) return strdup("The output callback is not set.");
78  else if (error == kCVReturnInvalidPixelFormat) return strdup("The requested pixelformat is not supported for the CVBuffer type.");
79  else if (error == kCVReturnInvalidSize) return strdup("The requested size (most likely too big) is not supported for the CVBuffer type.");
80  else if (error == kCVReturnInvalidPixelBufferAttributes) return strdup("A CVBuffer cannot be created with the given attributes.");
81  else if (error == kCVReturnPixelBufferNotOpenGLCompatible) return strdup("The Buffer cannot be used with OpenGL as either its size, pixelformat or attributes are not supported by OpenGL.");
82  else if (error == -6684 /*kCVReturnPixelBufferNotMetalCompatible*/) return strdup("The Buffer cannot be used with Metal as either its size, pixelformat or attributes are not supported by Metal.");
83  else if (error == kCVReturnWouldExceedAllocationThreshold) return strdup("The allocation request failed because it would have exceeded a specified allocation threshold (see kCVPixelBufferPoolAllocationThresholdKey).");
84  else if (error == kCVReturnPoolAllocationFailed) return strdup("The allocation for the buffer pool failed. Most likely because of lack of resources. Check if your parameters are in range.");
85  else if (error == kCVReturnInvalidPoolAttributes) return strdup("A CVBufferPool cannot be created with the given attributes.");
86  else if (error == -6692 /*kCVReturnRetry*/) return strdup("A scan hasn't completely traversed the CVBufferPool due to a concurrent operation. The client can retry the scan.");
87 
88  // CMIOHardware.h
89  // AudioHardwareBase.h
90  else if (error == kCMIOHardwareNotStoppedError) return strdup("The function call requires that the hardware be stopped but it isn't.");
91  else if (error == kCMIOHardwareNotRunningError) return strdup("The function call requires that the hardware be running but it isn't.");
92  else if (error == kCMIOHardwareUnspecifiedError) return strdup("The function call failed while doing something that doesn't provide any error messages.");
93  else if (error == kCMIOHardwareUnknownPropertyError) return strdup("The object doesn't know about the property at the given address.");
94  else if (error == kCMIOHardwareBadPropertySizeError) return strdup("An improperly sized buffer was provided when accessing the data of a property.");
95  else if (error == kCMIOHardwareIllegalOperationError) return strdup("The requested operation couldn't be completed.");
96  else if (error == kCMIOHardwareBadObjectError) return strdup("The CMIOObjectID passed to the function doesn't map to a valid CMIOObject.");
97  else if (error == kCMIOHardwareBadDeviceError) return strdup("The CMIODeviceID passed to the function doesn't map to a valid CMIODevice.");
98  else if (error == kCMIOHardwareBadStreamError) return strdup("The CMIODeviceID passed to the function doesn't map to a valid CMIOStream.");
99  else if (error == kCMIOHardwareUnsupportedOperationError) return strdup("The device doesn't support the requested operation.");
100  else if (error == kCMIOHardwareSuspendedBySystemError) return strdup("The function call failed because because access been suspended by the system.");
101  else if (error == kCMIODeviceUnsupportedFormatError) return strdup("The CMIOStream doesn't support the requested format.");
102  else if (error == kCMIODevicePermissionsError) return strdup("The requested operation can't be completed because the process doesn't have permission.");
103 
104  // AudioCodec.h
105  else if (error == 561214580 /*kAudioCodecStateError*/) return strdup("Codec state error.");
106  else if (error == 560100710 /*kAudioCodecNotEnoughBufferSpaceError*/) return strdup("Not enough buffer space.");
107 
108  // CGError.h
109  else if (error == kCGErrorFailure) return strdup("Failure.");
110  else if (error == kCGErrorIllegalArgument) return strdup("Illegal argument.");
111  else if (error == kCGErrorInvalidConnection) return strdup("Invalid connection.");
112  else if (error == kCGErrorInvalidContext) return strdup("Invalid context.");
113  else if (error == kCGErrorCannotComplete) return strdup("Cannot complete.");
114  else if (error == kCGErrorNotImplemented) return strdup("Not implemented.");
115  else if (error == kCGErrorRangeCheck) return strdup("Range check.");
116  else if (error == kCGErrorTypeCheck) return strdup("Type check.");
117  else if (error == kCGErrorInvalidOperation) return strdup("Invalid operation.");
118  else if (error == kCGErrorNoneAvailable) return strdup("None available.");
119 
120  // CSCommon.h
121  else if (error == errSecCSUnimplemented) return strdup("unimplemented code signing feature");
122  else if (error == errSecCSInvalidObjectRef) return strdup("invalid API object reference");
123  else if (error == errSecCSInvalidFlags) return strdup("invalid or inappropriate API flag(s) specified");
124  else if (error == errSecCSObjectRequired) return strdup("a required pointer argument was NULL");
125  else if (error == errSecCSStaticCodeNotFound) return strdup("cannot find code object on disk");
126  else if (error == errSecCSUnsupportedGuestAttributes) return strdup("cannot locate guests using this attribute set");
127  else if (error == errSecCSInvalidAttributeValues) return strdup("given attribute values are invalid");
128  else if (error == errSecCSNoSuchCode) return strdup("host has no guest with the requested attributes");
129  else if (error == errSecCSMultipleGuests) return strdup("ambiguous guest specification (host has multiple guests with these attribute values)");
130  else if (error == errSecCSGuestInvalid) return strdup("code identity has been invalidated");
131  else if (error == errSecCSUnsigned) return strdup("code object is not signed at all");
132  else if (error == errSecCSSignatureFailed) return strdup("invalid signature (code or signature have been modified)");
133  else if (error == errSecCSSignatureNotVerifiable) return strdup("the code cannot be read by the verifier (file system permissions etc.)");
134  else if (error == errSecCSSignatureUnsupported) return strdup("unsupported type or version of signature");
135  else if (error == errSecCSBadDictionaryFormat) return strdup("a required plist file or resource is malformed");
136  else if (error == errSecCSResourcesNotSealed) return strdup("resources are present but not sealed by signature");
137  else if (error == errSecCSResourcesNotFound) return strdup("code has no resources but signature indicates they must be present");
138  else if (error == errSecCSResourcesInvalid) return strdup("the sealed resource directory is invalid");
139  else if (error == errSecCSBadResource) return strdup("a sealed resource is missing or invalid");
140  else if (error == errSecCSResourceRulesInvalid) return strdup("invalid resource specification rule(s)");
141  else if (error == errSecCSReqInvalid) return strdup("invalid or corrupted code requirement(s)");
142  else if (error == errSecCSReqUnsupported) return strdup("unsupported type or version of code requirement(s)");
143  else if (error == errSecCSReqFailed) return strdup("code failed to satisfy specified code requirement(s)");
144  else if (error == errSecCSBadObjectFormat) return strdup("object file format unrecognized, invalid, or unsuitable");
145  else if (error == errSecCSInternalError) return strdup("internal error in Code Signing subsystem");
146  else if (error == errSecCSHostReject) return strdup("code rejected its host");
147  else if (error == errSecCSNotAHost) return strdup("attempt to specify guest of code that is not a host");
148  else if (error == errSecCSSignatureInvalid) return strdup("invalid or unsupported format for signature");
149  else if (error == errSecCSHostProtocolRelativePath) return strdup("host protocol violation - absolute guest path required");
150  else if (error == errSecCSHostProtocolContradiction) return strdup("host protocol violation - contradictory hosting modes");
151  else if (error == errSecCSHostProtocolDedicationError) return strdup("host protocol violation - operation not allowed with/for a dedicated guest");
152  else if (error == errSecCSHostProtocolNotProxy) return strdup("host protocol violation - proxy hosting not engaged");
153  else if (error == errSecCSHostProtocolStateError) return strdup("host protocol violation - invalid guest state change request");
154  else if (error == errSecCSHostProtocolUnrelated) return strdup("host protocol violation - the given guest is not a guest of the given host");
155  else if (error == errSecCSNotSupported) return strdup("operation inapplicable or not supported for this type of code");
156  else if (error == errSecCSCMSTooLarge) return strdup("signature too large to embed (size limitation of on-disk representation)");
157  else if (error == errSecCSHostProtocolInvalidHash) return strdup("host protocol violation - invalid guest hash");
158  else if (error == errSecCSStaticCodeChanged) return strdup("the code on disk does not match what is running");
159  else if (error == errSecCSDBDenied) return strdup("permission to use a database denied");
160  else if (error == errSecCSDBAccess) return strdup("cannot access a database");
161  else if (error == errSecCSSigDBDenied) return strdup("SigDB denied");
162  else if (error == errSecCSSigDBAccess) return strdup("SigDB access");
163  else if (error == errSecCSHostProtocolInvalidAttribute) return strdup("host returned invalid or inconsistent guest attributes");
164  else if (error == errSecCSInfoPlistFailed) return strdup("invalid Info.plist (plist or signature have been modified)");
165  else if (error == errSecCSNoMainExecutable) return strdup("the code has no main executable file");
166  else if (error == errSecCSBadBundleFormat) return strdup("bundle format unrecognized, invalid, or unsuitable");
167  else if (error == errSecCSNoMatches) return strdup("no matches for search or update operation");
168  else if (error == errSecCSFileHardQuarantined) return strdup("File created by an AppSandbox, exec/open not allowed");
169  else if (error == errSecCSOutdated) return strdup("presented data is out of date");
170  else if (error == errSecCSDbCorrupt) return strdup("a system database or file is corrupt");
171  else if (error == errSecCSResourceDirectoryFailed) return strdup("invalid resource directory (directory or signature have been modified)");
172  else if (error == errSecCSUnsignedNestedCode) return strdup("nested code is unsigned");
173  else if (error == errSecCSBadNestedCode) return strdup("nested code is modified or invalid");
174  else if (error == errSecCSBadCallbackValue) return strdup("monitor callback returned invalid value");
175  else if (error == errSecCSHelperFailed) return strdup("the codesign_allocate helper tool cannot be found or used");
176  else if (error == errSecCSVetoed) return strdup("vetoed");
177  else if (error == errSecCSBadLVArch) return strdup("library validation flag cannot be used with an i386 binary");
178  else if (error == errSecCSResourceNotSupported) return strdup("unsupported resource found (something not a directory, file or symlink)");
179  else if (error == errSecCSRegularFile) return strdup("the main executable or Info.plist must be a regular file (no symlinks, etc.)");
180  else if (error == errSecCSUnsealedAppRoot) return strdup("unsealed contents present in the bundle root");
181  else if (error == errSecCSWeakResourceRules) return strdup("resource envelope is obsolete (custom omit rules)");
182  else if (error == errSecCSDSStoreSymlink) return strdup(".DS_Store files cannot be a symlink ");
183  else if (error == errSecCSAmbiguousBundleFormat) return strdup("bundle format is ambiguous (could be app or framework)");
184  else if (error == errSecCSBadMainExecutable) return strdup("main executable failed strict validation");
185  else if (error == errSecCSBadFrameworkVersion) return strdup("embedded framework contains modified or invalid version");
186  else if (error == errSecCSUnsealedFrameworkRoot) return strdup("unsealed contents present in the root directory of an embedded framework");
187  else if (error == errSecCSWeakResourceEnvelope) return strdup("resource envelope is obsolete (version 1 signature)");
188  else if (error == errSecCSCancelled) return strdup("operation was terminated by explicit cancellation");
189 
190  char *errorString = (char *)calloc(1, 12); // ceil(log10(INT_MAX)) + 1 (optional negative sign) + 1 (null terminator)
191 
192  *(UInt32 *)(errorString + 1) = CFSwapInt32HostToBig(error);
193  if (isprint(errorString[1]) && isprint(errorString[2]) && isprint(errorString[3]) && isprint(errorString[4]))
194  {
195  errorString[0] = errorString[5] = '\'';
196  errorString[6] = '\0';
197  }
198  else
199  sprintf(errorString, "%d", (int)error);
200 
201  return errorString;
202 }