{"record":{"id":"29f6e1138a9c363e","repo":"toeverything/AFFiNE","slug":"invalid-mobile-payload-token-empty-file-path","errorCode":null,"errorMessage":"Invalid mobile payload token: empty file path","messagePattern":"Invalid mobile payload token: empty file path","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/frontend/apps/mobile-shared/src/nbstore/payload.ts","lineNumber":16,"sourceCode":"import { base64ToUint8Array } from '@affine/core/modules/workspace-engine';\nimport { Capacitor } from '@capacitor/core';\n\nexport const MOBILE_BLOB_FILE_PREFIX = '__AFFINE_BLOB_FILE__:';\nexport const MOBILE_PAYLOAD_INLINE_THRESHOLD_BYTES = 1024 * 1024;\nconst MOBILE_PAYLOAD_CACHE_DIR = 'nbstore-blob-cache';\nconst MOBILE_PAYLOAD_BUCKET_PATTERN = /^[0-9a-f]{16}$/;\nconst MOBILE_PAYLOAD_FILE_PATTERN = /^[0-9a-f]{16}\\.blob$/;\nconst MOBILE_PAYLOAD_PARENT_DIRS = new Set(['cache', 'Caches', 'T', 'tmp']);\nconst MOBILE_ANDROID_PACKAGE_PATTERN =\n  /^[A-Za-z][A-Za-z0-9_]*(\\.[A-Za-z][A-Za-z0-9_]*)+$/;\n\nfunction normalizeTokenFilePath(rawPath: string): string {\n  const trimmedPath = rawPath.trim();\n  if (!trimmedPath) {\n    throw new Error('Invalid mobile payload token: empty file path');\n  }\n\n  return trimmedPath.startsWith('file://')\n    ? trimmedPath\n    : `file://${trimmedPath}`;\n}\n\nfunction assertMobileCachePath(fileUrl: string): void {\n  let pathname: string;\n  try {\n    const parsedUrl = new URL(fileUrl);\n    if (parsedUrl.protocol !== 'file:') {\n      throw new Error('unexpected protocol');\n    }\n    pathname = parsedUrl.pathname;\n  } catch {\n    throw new Error('Invalid mobile payload token: malformed file URL');\n  }","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/frontend/apps/mobile-shared/src/nbstore/payload.ts#L1-L34","documentation":"normalizeTokenFilePath validates mobile blob-file tokens; when the token's file path portion is empty after stripping the MOBILE_BLOB_FILE_PREFIX, the token is malformed and this Error is thrown. Used by normalizedPath.","triggerScenarios":"Thrown in normalizeTokenFilePath when a mobile nbstore blob payload token starts with the __AFFINE_BLOB_FILE__ prefix but the remainder trims to an empty string, so no file path can be derived.","commonSituations":"Seen on mobile when a corrupted or truncated blob reference is stored instead of a real cache file path. Re-fetching or re-uploading the blob regenerates a valid token.","solutions":["Ensure the payload token contains a non-empty file path before calling the payload reader.","Validate the token payload on the producer side so empty paths are never emitted."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}