{"record":{"id":"26b5368d48343dca","repo":"laurent22/joplin","slug":"resource-file-was-not-created-targetpath","errorCode":null,"errorMessage":"Resource file was not created: ${targetPath}","messagePattern":"Resource file was not created: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/app-mobile/utils/shim-init-react/shimInitShared.ts","lineNumber":129,"sourceCode":"\n\t\tconst ext = fileExtension(filePath);\n\t\tconst mimeType = defaultProps.mime ?? mimeUtils.fromFileExtension(ext) ?? 'image/jpeg';\n\n\t\tlet resource = Resource.new();\n\t\tresource.id = resourceId;\n\t\tresource.mime = mimeType;\n\t\tresource.title = basename(filePath);\n\t\tresource.file_extension = ext;\n\n\t\tconst targetPath = Resource.fullPath(resource);\n\t\tawait shim.fsDriver().copy(filePath, targetPath);\n\n\t\tif (defaultProps) {\n\t\t\tresource = { ...resource, ...defaultProps };\n\t\t}\n\n\t\tconst itDoes = await shim.fsDriver().waitTillExists(targetPath);\n\t\tif (!itDoes) throw new Error(`Resource file was not created: ${targetPath}`);\n\n\t\tconst fileStat = await shim.fsDriver().stat(targetPath);\n\t\tresource.size = fileStat.size;\n\n\t\tresource = await Resource.save(resource, { isNew: true });\n\n\t\treturn resource;\n\t};\n\n\tshim.detectAndSetLocale = (settings: typeof Setting) => {\n\t\t// [\n\t\t// \t{\n\t\t// \t\t\"countryCode\": \"US\",\n\t\t// \t\t\"isRTL\": false,\n\t\t// \t\t\"languageCode\": \"fr\",\n\t\t// \t\t\"languageTag\": \"fr-US\"\n\t\t// \t},\n\t\t// \t{","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/laurent22/joplin/blob/2654b33620775080d1d59c552259d41e33dad3d2/packages/app-mobile/utils/shim-init-react/shimInitShared.ts#L111-L147","documentation":"Thrown by the mobile shim.createResourceFromPath after copying the source file to the resource target path: shim.fsDriver().waitTillExists(targetPath) returned false, meaning the file did not appear within the poll window despite copy() not throwing. This guards against silent copy failures on mobile where the FS write is async at the native layer.","triggerScenarios":"shim.fsDriver().copy() silently failed (no throw but no file written); the target directory does not exist or is read-only; storage full so the copy produced nothing; a content:// source URI could not be resolved by the native copy; waitTillExists poll interval/timeout is too short for slow storage.","commonSituations":"Creating a resource from a camera/gallery URI on Android where the content provider revoked access; target resource dir on external storage that was unmounted; low-disk condition; a React Native FS driver bug returning success without writing.","solutions":["Verify the source filePath exists and is readable before calling createResourceFromPath.","Ensure the resource target directory (Resource.fullPath parent) exists and is writable — call shim.fsDriver().mkdir(dirname(targetPath)) if needed.","Check available disk space on the device before resource creation.","If the source is a content:// URI, copy it to a temp file in the app's sandbox first, then pass that temp path.","Increase the waitTillExists timeout if the device storage is consistently slow."],"exampleFix":"// before\nconst resource = await shim.createResourceFromPath(contentUri);\n// after — materialize the content URI into a real file first\nconst tmp = `${shim.fsDriver().getTempDir()}/${uuid.create()}.jpg`;\nawait shim.fsDriver().copy(contentUri, tmp);\nif (!(await shim.fsDriver().exists(tmp))) throw new Error('Source unreadable');\nconst resource = await shim.createResourceFromPath(tmp);","handlingStrategy":"validation","validationCode":"const fsDriver = shim.fsDriver();\nif (!(await fsDriver.exists(filePath))) throw new Error(`Source not found: ${filePath}`);\nconst targetDir = dirname(Resource.fullPath(Resource.New()));\nif (!(await fsDriver.exists(targetDir))) await fsDriver.mkdir(targetDir);\nawait shim.createResourceFromPath(filePath);","typeGuard":"function isReadablePath(p) { return typeof p === 'string' && p.length > 0; }","tryCatchPattern":"try {\n  return await shim.createResourceFromPath(filePath);\n} catch (e) {\n  if (/Resource file was not created/.test(e.message)) {\n    // materialize a content:// URI to a temp file first, then retry\n    const tmp = `${shim.fsDriver().getTempDir()}/${uuid.create()}`;\n    await shim.fsDriver().copy(filePath, tmp);\n    return shim.createResourceFromPath(tmp);\n  }\n  throw e;\n}","preventionTips":["Convert content:// URIs to a sandbox temp file before calling createResourceFromPath.","Ensure the resource target directory exists and is writable.","Check free disk space before resource creation."],"tags":["mobile","filesystem","resource","android","content-uri"],"backgroundTag":null,"analyzedSha":"2654b33620775080d1d59c552259d41e33dad3d2","analyzedAt":"2026-08-12T14:26:46.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}