Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Audiobook Meta File Access Error - PathNotFoundException #82

Closed
sujansujan opened this issue Nov 6, 2024 · 31 comments · Fixed by #120
Closed

[BUG] Audiobook Meta File Access Error - PathNotFoundException #82

sujansujan opened this issue Nov 6, 2024 · 31 comments · Fixed by #120
Assignees
Labels
bug Something isn't working

Comments

@sujansujan
Copy link

sujansujan commented Nov 6, 2024

Screenshot_20241106-073335
Bug Report

Description of the Issue
The application is encountering a critical error when attempting to access an audiobook's metadata file. The error occurs when trying to open a meta.json file for an audiobook in the emulated storage directory. I am on android.

Steps to Reproduce
Outline the steps needed to reproduce this issue:

  1. Download audiobook for offline listen
  2. try to open the book

Expected Behavior
Open audiobook page.

Observed Behavior
Error Type: PathNotFoundException
File Path: /storage/emulated/0/Audiobooks/3bf79808-ad8f-4242-910f-def1e17fd1c1/meta.json
System Error: No such file or directory (errno = 2)
Device Status: Android device

Device and Platform Details

  • Device Type: SmartPhone
  • Operating System: android 14
  • App Version: 1.6.4

Additional Context or Screenshots

Additional Logs

2024-11-06T07:36:50.790814 AppLifecycleState Detached
2024-11-06T07:36:50.614354 AppLifecycleState Detached
2024-11-06T07:35:49.437737 item_view PathNotFoundException: Cannot open file, path = '/storage/emulated/0/Audiobooks/3bf79808-ad8f-4242-910f-def1e17fd1c1/meta.json' (OS Error: No such file or directory, errno = 2)
#0      _File.throwIfError (dart:io/file_impl.dart:675)
#1      _File.openSync (dart:io/file_impl.dart:490)
#2      _File.readAsBytesSync (dart:io/file_impl.dart:574)
#3      _File.readAsStringSync (dart:io/file_impl.dart:624)
#4      itemProvider.<anonymous closure> (package:abs_flutter/provider/library_item_provider.dart:63)
#5      FamilyBase.call.<anonymous closure> (package:riverpod/src/framework/family.dart:150)
#6      FutureProvider._create (package:riverpod/src/future_provider/base.dart:65)
#7      FutureProviderElement.create.<anonymous closure> (package:riverpod/src/future_provider/base.dart:107)
#8      FutureHandlerProviderElementMixin.handleFuture.<anonymous closure> (package:riverpod/src/async_notifier/base.dart:334)
#9      FutureHandlerProviderElementMixin._handleAsync (package:riverpod/src/async_notifier/base.dart:381)
#10     FutureHandlerProviderElementMixin.handleFuture (package:riverpod/src/async_notifier/base.dart:328)
#11     FutureProviderElement.create (package:riverpod/src/future_provider/base.dart:106)
#12     ProviderElementBase.buildState (package:riverpod/src/framework/element.dart:409)
#13     ProviderElementBase.mount (package:riverpod/src/framework/element.dart:226)
#14     _StateReader._create (package:riverpod/src/framework/container.dart:47)
#15     _StateReader.getElement (package:riverpod/src/framework/container.dart:35)
#16     ProviderContainer.readProviderElement (package:riverpod/src/framework/container.dart:479)
#17     ProviderBase.addListener (package:riverpod/src/framework/provider_base.dart:79)
#18     ProviderContainer.listen (package:riverpod/src/framework/container.dart:280)
#19     ConsumerStatefulElement.watch.<anonymous closure> (package:flutter_riverpod/src/consumer.dart:564)
#20     _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:543)
#21     ConsumerStatefulElement.watch (package:flutter_riverpod/src/consumer.dart:557)
#22     BookView.build (package:abs_flutter/features/library/item/book_view.dart:29)
@sujansujan sujansujan added the bug Something isn't working label Nov 6, 2024
@Vito0912
Copy link
Owner

Vito0912 commented Nov 6, 2024

Thank you for reporting this issue!

It sounds like you've set a custom download directory on an SD card. This may be causing either a parsing error when writing data to disk or a permissions issue. The actual error likely occurs during the media download process. Could you please provide the logs from when you download the item?

@sujansujan
Copy link
Author

sujansujan commented Nov 6, 2024

2024-11-06T07:36:50.790814 AppLifecycleState Detached
2024-11-06T07:36:50.614354 AppLifecycleState Detached
2024-11-06T07:35:49.437737 item_view PathNotFoundException: Cannot open file, path = '/storage/emulated/0/Audiobooks/3bf79808-ad8f-4242-910f-def1e17fd1c1/meta.json' (OS Error: No such file or directory, errno = 2)
#0      _File.throwIfError (dart:io/file_impl.dart:675)
#1      _File.openSync (dart:io/file_impl.dart:490)
#2      _File.readAsBytesSync (dart:io/file_impl.dart:574)
2024-11-06T07:34:50.028110 Unnamed ConnectionNotifier initialized
2024-11-06T07:34:50.023517 progress_provider getBookmarks
2024-11-06T07:34:50.023082 OfflineProgress Number of offline progress items: 1
2024-11-06T07:34:50.020120 progress_provider getProgress
2024-11-06T07:34:50.018220 init @ number of users 1
2024-11-06T07:34:50.008898 Unnamed Stop sending

Edited by Vito0912: Stripped code to make it more readable

@Vito0912
Copy link
Owner

Vito0912 commented Nov 6, 2024

I did not see anything suspicious.
I will try to reproduce the bug on an emulated device with an emulated SD card tomorrow.

@Vito0912
Copy link
Owner

Vito0912 commented Nov 6, 2024

I’m currently unable to reproduce the bug. I’ve just realized that /storage/emulated doesn’t necessarily indicate an SD card. Could you clarify if you’ve set a custom save location and/or installing the app on an SD card, to help me understand the issue better?

Ideally, the app shouldn’t populate this path if it lacks the required permissions (What it does in my case). This situation suggests it might have write access but not read access. But I am very unsure

@sujansujan
Copy link
Author

Save location is within Internal storage, not SD card. /storage/emulated/0/ is how path is shown in android.
i am also thinking the same about not havinng read permission. i even tried manually creating metadata.json file to check if it works, but it didnot.

@Vito0912
Copy link
Owner

Vito0912 commented Nov 7, 2024

So no meta.json is created at all?
is the actual media file downloaded?

@sujansujan
Copy link
Author

Meta.json is not created but the media file is downloaded.

@Vito0912
Copy link
Owner

Vito0912 commented Nov 8, 2024

Are you sure the above log includes the item download event? It seems unlikely that the media item could download without the meta.json file, and without any error message.

Additionally, the log statement log('Downloading to: $savePath ($baseDirectory)'); doesn’t appear in the logs, though it should if a download has actually started.

@sujansujan
Copy link
Author

i redownloaded again after deleting previous download. there is this line though. yes, I do get fully downloaded file in the path mentioned below and I can play it with external players like smart audiobook player

2024-11-09T07:20:59.010780 Unnamed DownloadInfo(index: 29886432, type: MediaTypeDownload.book, userId: e4f9cc1d-7d48-4e86-92b7-7b596349b801, displayName: Master of Puppets (Unabridged), filename: Master of Puppets_128_44100_Stereo.m4b, format: .m4b, libraryId: aae65e1f-ec22-46a5-86e9-9392a69ca5b6, libraryName: audiobooks, itemId: 3bf79808-ad8f-4242-910f-def1e17fd1c1, status: TaskStatus.complete, size: 694925372, episodeId: null, filePath: /storage/emulated/0/Audiobooks/3bf79808-ad8f-4242-910f-def1e17fd1c1/Master of Puppets_128_44100_Stereo.m4b, duration: null, bitrate: null, codec: null, mimeType: null, embeddedCoverArt: null)

@Vito0912
Copy link
Owner

Vito0912 commented Nov 9, 2024

I noticed that the statement log('Downloading to: $savePath ($baseDirectory)'); wasn’t functioning correctly in the released application. This will be fixed in the next release, which will also delete the download if it fails.

As for the other file not being created, I’m unable to diagnose the cause, as there’s no error handling in place to prevent a crash. It should crash if not createable. If the file isn’t being created, it may be related to your device’s file system. Could you try setting a custom folder in the settings of this app to see if that resolves the issue?

@sujansujan
Copy link
Author

same issue with custom folder. App streams well, i will just use that. downloading is a "good to have" but not a necessity.

@Vito0912
Copy link
Owner

Vito0912 commented Nov 11, 2024

Could you please share the new logs with the updated logging?

You can paste the logs like this for better formatting:
```
Your log here
```

@sujansujan
Copy link
Author

Screenshot_20241111-211250.png

2024-11-11T21:06:58.820163 Unnamed Downloading to: /storage/emulated/0/Buchable/3bf79808-ad8f-4242-910f-def1e17fd1c1 (BaseDirectory.root)
2024-11-11T21:06:57.891945 item_view Building item view for 3bf79808-ad8f-4242-910f-def1e17fd1c1

@Vito0912
Copy link
Owner

Why does it not log the error xD.
I will have to take a look if more people expierience the error. Thanks for now

@ExXxtr3me
Copy link

I have the same error. Strangely it works right after the download. When I closed the app it wasn't working anymore.

@Vito0912
Copy link
Owner

Vito0912 commented Nov 12, 2024

It caches the response, so it doesn't need to reload all the data, allowing it to display content immediately. This approach conserves data usage :)). That's why it does work right after. I'll run some additional tests on my device.
But I just tested it with the newest version on my device - downloaded via Play Store and have no issue at all. I don't even know where to search, because it seem to have write and read permission (As the file is downloaded).
Idk if you can do this, but it would be a help if you could build it from source in debug and check the real logs (I can only log so much via the logs provided to the users)

@Vito0912
Copy link
Owner

@LarryBetz and all,

The upcoming version, which should be available on the Play Store in about an hour, will address the crash issue but may not fully resolve the underlying error. I’m still uncertain if the media is available for playback then.

This update includes significantly more logging around the creation of meta.json. If you install the update, could you please share the updated logs? Thanks!

@ExXxtr3me
Copy link

The new version seems to be working, it's even playing my previously downloaded files.

@Vito0912
Copy link
Owner

It just does not crash anymore and streams the file now, if there is no meta.json.

Could you please look into the logs if there is an error. I made a really small change to file creation. Maybe this fixed it, but I don't think so.

Thank you very much!

@ExXxtr3me
Copy link

ExXxtr3me commented Nov 14, 2024

It just does not crash anymore and streams the file now, if there is no meta.json.

Could you please look into the logs if there is an error. I made a really small change to file creation. Maybe this fixed it, but I don't think so.

Thank you very much!

I'm not at home right now but I just disabled mobile data and was able to play the file. Although I have created an empty file called meta.json in the folder previously to test it. After deleting it the audiobook isn't working anymore, even with a new empty meta.json

@ExXxtr3me
Copy link

2024-11-15T13:22:13.788462 DownloadProvider Writing meta.json to: /storage/emulated/0/Audiobooks/f47db04f-6fe2-4d4c-8e3f-7285d035c3a7/meta.json
2024-11-15T13:22:13.788450 DownloadProvider Creating directory: /storage/emulated/0/Audiobooks/f47db04f-6fe2-4d4c-8e3f-7285d035c3a7
2024-11-15T13:22:13.747315 DownloadProvider Saving meta.json to: /storage/emulated/0/Audiobooks/f47db04f-6fe2-4d4c-8e3f-7285d035c3a7/meta.json
2024-11-15T13:22:13.747270 DownloadProvider Does safe json?: /storage/emulated/0/Audiobooks/f47db04f-6fe2-4d4c-8e3f-7285d035c3a7/meta.json
2024-11-15T13:22:13.705369 Unnamed Downloading to: /storage/emulated/0/Audiobooks/f47db04f-6fe2-4d4c-8e3f-7285d035c3a7 (BaseDirectory.root)
2024-11-15T13:22:12.286640 removeDownload Deleting folder: /storage/emulated/0/Audiobooks/f47db04f-6fe2-4d4c-8e3f-7285d035c3a7
2024-11-15T13:22:09.837092 item_view Building item view for f47db04f-6fe2-4d4c-8e3f-7285d035c3a7

@ExXxtr3me
Copy link

ExXxtr3me commented Nov 15, 2024

Here is the log from a new download. Playing the book offline is not working.

@Paraxes
Copy link

Paraxes commented Nov 27, 2024

I also get the error, when trying to save to an external SD card. Same errors as ExXxtr3me posted. The newest version of Buchable did not fix it.

@Vito0912
Copy link
Owner

Will look into it on Friday

@Vito0912
Copy link
Owner

Vito0912 commented Dec 1, 2024

It's not yet in the newest release as I need to test a bit more

@Paraxes
Copy link

Paraxes commented Dec 1, 2024

Then I apologize. I was too quick. Sorry, just wanted to let you know. I deleted the post and will update if the problem persists after you updated it :)

@Vito0912
Copy link
Owner

Vito0912 commented Dec 1, 2024

@Paraxes If you're interested, you can test the build for that version. It would be incredibly helpful in diagnosing whether this issue is finally resolved, as I can't replicate the problem myself, though it seems to affect many others.

To try it out, simply download the android-apk artifact and install it. Note that you'll need to uninstall the Play Store version before installing the APK.

If everything works smoothly and you don't encounter any issues, I'll go ahead and close the PR, and the fix will be included in the next release.
https://github.com/Vito0912/abs_flutter/actions/runs/12096438223

@Paraxes
Copy link

Paraxes commented Dec 1, 2024

I wish I had better news to share, but sadly, the error persists:

Screenshot_20241201-162513

@Vito0912
Copy link
Owner

Vito0912 commented Dec 1, 2024

Could I connect with you on Discord/Mail or another platform you prefer? That way, I can send you two additional versions of the build for testing if you would test them quickly?
You can send me a mail to [email protected]

@Paraxes
Copy link

Paraxes commented Dec 1, 2024

Sure thing. I just sent you an email.

@Vito0912
Copy link
Owner

Vito0912 commented Dec 3, 2024

I’ve identified the issue, but I’m currently unsure if it can be resolved in the next release.
It seems this might require a complete overhaul of the download process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants