{"record":{"id":"6943ee45d0f11c1b","repo":"bazelbuild/bazel","slug":"error-s-n","errorCode":null,"errorMessage":"error: %s\\n","messagePattern":"error: (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/osx/xcode_locator.m","lineNumber":137,"sourceCode":"// Searches for all available Xcodes in the system and returns a dictionary that\n// maps version identifiers of any form (X, X.Y, and X.Y.Z) to the directory\n// where the Xcode bundle lives.\n//\n// If there is a problem locating the Xcodes, prints one or more error messages\n// and returns nil.\nstatic NSMutableDictionary<NSString *, XcodeVersionEntry *> *FindXcodes()\n  __attribute((ns_returns_retained)) {\n  CFStringRef cfBundleID = CFSTR(\"com.apple.dt.Xcode\");\n  NSString *bundleID = (__bridge NSString *)cfBundleID;\n\n  NSMutableDictionary<NSString *, XcodeVersionEntry *> *dict =\n      [[NSMutableDictionary alloc] init];\n  CFErrorRef cfError;\n  NSArray *array = CFBridgingRelease(LSCopyApplicationURLsForBundleIdentifier(\n      cfBundleID, &cfError));\n  if (array == nil) {\n    NSError *nsError = (__bridge NSError *)cfError;\n    fprintf(stderr, \"error: %s\\n\", nsError.description.UTF8String);\n    return nil;\n  }\n\n  // Scan all bundles but delay returning in case of errors until we are\n  // done. This is to let us log details about all the bundles that were\n  // processed so that a faulty bundle doesn't hide useful information about\n  // other bundles that were found.\n  BOOL errors = NO;\n  for (NSURL *url in array) {\n    NSArray *contents = [\n      [NSFileManager defaultManager] contentsOfDirectoryAtURL:url\n                                   includingPropertiesForKeys:nil\n                                                      options:0\n                                                        error:nil];\n    NSLog(@\"Found bundle %@ in %@; contents on disk: %@\",\n          bundleID, url, contents);\n\n    NSBundle *bundle = [NSBundle bundleWithURL:url];","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/tools/osx/xcode_locator.m#L119-L155","documentation":"In xcode_locator.m, FindXcodes asks LaunchServices (LSCopyApplicationURLsForBundleIdentifier for 'com.apple.dt.Xcode') to enumerate installed Xcodes; if the call returns no array it bridges the CFError, prints 'error: <description>' to stderr, and returns nil, which fails Xcode detection for the Bazel/Xcode integration.","triggerScenarios":"Running xcode_locator on a machine where LaunchServices cannot resolve the Xcode bundle id: Xcode not installed, Xcode never launched/registered, a damaged LaunchServices database, or an incomplete .xip extraction that never registered with LaunchServices.","commonSituations":"Fresh macOS CI images with Xcode installed by unzipping rather than proper installation; corrupted LaunchServices after OS upgrades; Xcode betas installed under a different bundle identifier; environments where /Applications/Xcode.app was renamed.","solutions":["Install Xcode properly from .xip into /Applications and launch it once so it registers with LaunchServices.","Run 'xcode-select -p' and 'xcodebuild -version' to confirm a healthy install, and sudo xcode-select -s /Applications/Xcode.app.","Reset LaunchServices registration: /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user, then relaunch Xcode.","Ensure the app bundle id is exactly com.apple.dt.Xcode (renamed or wrapper bundles will not match).","On CI, prefer pre-provisioned images with Xcode registered rather than ad-hoc copies."],"exampleFix":"# before: bazel build //ios:app  -> xcode_locator prints 'error: ...'\nsudo xcode-select -s /Applications/Xcode.app\nxcodebuild -version   # verify\nbazel clean && bazel build //ios:app","handlingStrategy":"fallback","validationCode":"// shell-level precheck before relying on xcode_locator\nif ! xcode-select -p >/dev/null 2>&1 || ! xcodebuild -version >/dev/null 2>&1; then\n  echo \"Xcode not properly installed/selected\" >&2; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Launch Xcode once after install so LaunchServices registers it.","Pin xcode-select to the intended /Applications/Xcode.app.","On CI images, install Xcode from .xip rather than copying bundles.","If detection still fails, reset LaunchServices with lsregister and relaunch Xcode."],"tags":["macos","xcode","objective-c","launchservices","toolchain-detection"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}