rn-watch-connectv2.0

Error codes

Every Error code the library reports, and how to handle errors safely.

Every failure has a stable Error code in code. You'll find it on errors that are thrown, on errors a Promise rejects with, and on the error in events such as onFileTransferFinished and onFileReceiveFailed.

Match on code, never on message

message is for people, and it can change between versions. Functions that throw directly also get Expo's prefix in their message: "Calling the 'transferFile' function has failed → Caused by: …". code stays the same.

The same failure has the same code whichever function reports it. For example, sendMessage and sendMessageWithoutReply both use ERR_WATCH_NOT_REACHABLE.

WatchConnectErrorCode

import { type WatchConnectErrorCode } from "rn-watch-connect";

The TypeScript union of every code on this page. Use it to type the codes you check, so a misspelled code fails to compile.

Example

import , { type  } from "rn-watch-connect";

function (: unknown):  | undefined {
  return ( as { ?:  } | null)?.;
}

try {
  await .({ : 1 });
} catch () {
  switch (()) {
    case "ERR_WATCH_NOT_REACHABLE":
      // Try again later, or use transferUserInfo, which doesn't need the Watch to be reachable.
      break;
    case "ERR_UNSUPPORTED_PLATFORM":
      // Not on iOS: hide your Watch features.
      break;
    default:
      throw ;
  }
}

The library's own codes

CodeWhenReported by
ERR_WATCH_NOT_REACHABLEA Message or Data Message was sent while the Watch isn't reachable. Nothing was sent.sendMessage, sendMessageWithoutReply, sendDataMessage, sendDataMessageWithoutReply
ERR_REPLY_NOT_PENDINGA Reply was sent for a Message already replied to, or no longer waiting for a Reply.The reply function of onMessageWithReply and onDataMessageWithReply, and the deprecated replyTo… methods
ERR_INVALID_BASE64A Data Message or data Reply isn't valid base64. message says why.Data Messages
ERR_INVALID_TRANSFER_IDThe id isn't an outstanding Transfer: already delivered, already cancelled, or from an earlier app run.cancelUserInfoTransfer, cancelFileTransfer
ERR_INVALID_FILE_URLThe file URL can't be read.transferFile
ERR_FILE_NOT_FOUNDThere's no file at the URL.transferFile
ERR_TRANSFER_CANCELLEDThe Transfer was cancelled.The finish events: onUserInfoTransferFinished, onFileTransferFinished
ERR_INSUFFICIENT_SPACEThe iPhone is out of storage, so a file from the Watch couldn't be kept. (This is also WatchConnectivity's own code for running out of space.)onFileReceiveFailed
ERR_FILE_RECEIVE_FAILEDA file from the Watch couldn't be kept, for another reason.onFileReceiveFailed
ERR_UNSUPPORTED_PLATFORMA method was called on a platform other than iOS.Every method
ERR_UNEXPECTEDAny other failure.Any method

WatchConnectivity's codes

WatchConnectivity's own errors, for example when sending, when updating the Application Context, or in finish events, use ERR_ plus the name of Apple's WCError.Code. Its notReachable uses the library's ERR_WATCH_NOT_REACHABLE, so one failure has one code.

CodeApple's WCError.CodeWhen
ERR_GENERIC_ERRORgenericErrorAn unknown problem.
ERR_SESSION_NOT_SUPPORTEDsessionNotSupportedThis iPhone doesn't support WatchConnectivity.
ERR_SESSION_MISSING_DELEGATEsessionMissingDelegateThe Session has no delegate to handle it.
ERR_SESSION_NOT_ACTIVATEDsessionNotActivatedThe Session isn't activated.
ERR_SESSION_INACTIVEsessionInactiveThe Session is inactive.
ERR_DEVICE_NOT_PAIREDdeviceNotPairedNo Apple Watch is paired with this iPhone.
ERR_WATCH_APP_NOT_INSTALLEDwatchAppNotInstalledYour Watch app isn't installed on the paired Watch.
ERR_COMPANION_APP_NOT_INSTALLEDcompanionAppNotInstalledThe companion app isn't installed on the other side.
ERR_WATCH_ONLY_APPwatchOnlyAppThe Watch app is a watch-only app, with no iPhone app to talk to.
ERR_INVALID_PARAMETERinvalidParameterA parameter is invalid.
ERR_PAYLOAD_TOO_LARGEpayloadTooLargeWhat you sent is over WatchConnectivity's size limit.
ERR_PAYLOAD_UNSUPPORTED_TYPESpayloadUnsupportedTypesA dictionary contains a value WatchConnectivity can't carry.
ERR_MESSAGE_REPLY_FAILEDmessageReplyFailedThe Reply couldn't be returned.
ERR_MESSAGE_REPLY_TIMED_OUTmessageReplyTimedOutThe other side didn't reply in time.
ERR_FILE_ACCESS_DENIEDfileAccessDeniedThe file couldn't be read for a File Transfer.
ERR_DELIVERY_FAILEDdeliveryFailedThe Transfer couldn't be delivered.
ERR_INSUFFICIENT_SPACEinsufficientSpaceThe receiving side doesn't have enough space to store it.
ERR_TRANSFER_TIMED_OUTtransferTimedOutThe Transfer hit its time limit before it finished.

On this page