How to debug an app

I have an app that isn’t working as expected. How do I go about debugging this? This issue isn’t currently generating anything in nextcloud.log or php8.1-fpm.log. I have tried increasing the log level with loglevel => '0' in config/config.php. I have also tried setting log_level = debug in /etc/php/8.1/fpm/php-fpm.conf (and examined /var/log/php8.1-fpm.log). I have also tried setting catch_workers_output = yes in /etc/php/8.1/fpm/pool.d/www.conf. None of this produces anything at all about the app in question. I know this app is running PHP scripts so how can I see the logging output of them?

Nextcloud version: 24.0.5.1
Operating system and version: Debian 11
Apache or nginx version: 2.4.54 (Debian repo)
PHP version: 8.1.14 (Debian repo)

What app are you talking about? It out punished somewhere?

From your words i get the impression, you are not talking of an app of yourself but a foreign app, that is already pre-existing.

In any case, there are different reasons why am app logs things. For one, if there is a syntactical error in the PHP code, the interpreter can no longer continue working on it. Then, you will find messages in various locations automatically, e.g. the Nextcloud Los as described.

If the app is technically working without major errors, this is some different issue. Then, the app will not generate any logging by default. It can to indicate special situations of various level but this must be programmed in terms of PHP code.

Without more information of is hard to give advice on what to do. If you really want to debug, a debugger (xdebug) or a trace might be feasible. Or simply a look at the console in the browser might give some insight. It depends on the exact issue and what you want to achieve.

So: please be a bit more specific about

  1. What app you are taking about
  2. What the problem is
  3. What you want to achieve (if not obvious from the big report).

Christian

1 Like

Sorry for not being clear enough. The app in question is the Memories app (i.e. GitHub - pulsejet/memories: Fast, modern and advanced photo management suite. Runs as a Nextcloud app.). And the problem is videos are not playing. I get a pretty generic error in the browser window (“The media could not be loaded, either because the server or network failed or because the format is not supported”). Doesn’t matter which browser or OS I use, same error. I have transcoding turned off as I’m running Nextcloud on an RPi and it’s not powerful enough for that. All my videos are in webm format (vp8 video, vorbis audio codecs). Have also tried an mp4 video, that didn’t work either. The webm videos all play fine in the built-in Nextcloud Files app. Or if I download them and open them directly in the web browser they also play fine.

OK, now we are getting closer.

Have you tested the playing with the developer console open? Are there any messages/warnings popping up?
Can you check if the backend sends bad data for some reason?

Explanation/motivation:
I want to separate the problem between backend (PHP) and frontend (HTML/JS/Vue). Check if the backend sends any sort of valid data. Maybe compare with an image (that seems to work). The goal is not to locate the problem yet but to narrow down the problem to a reproducible and minimal incident that will trigger the problem.

2 Likes

OK in the browser console I get the following output when trying to play a video:

VIDEOJS: WARN: The element supplied is not included in the DOM
...
HTTP "Content-Type" of "text/html" is not supported. Load of media resource https://mydomainname.com/index.php/remote.php/dav/files/ncp/InstantUpload/DCIM/VID-20220530-WA0000.webm failed.
VIDEOJS: ERROR: (CODE:4 MEDIA_ERR_SRC_NOT_SUPPORTED) The media could not be loaded, either because the server or network failed or because the format is not supported.
Uncaught (in promise) DOMException: The media resource indicated by the src attribute or assigned media provider object was not suitable.

Interestingly trying to open the URL contained on the first line of that output causes a redirection to the Nextcloud dashboard (index.php/apps/dashboard). However I think this is possibly standard behaviour when trying to access a Webdav URL directly in a browser. Using the browser console again I can see that the Files app (which the video plays in correctly) doesn’t use Webdav to access videos. Hope that answers all of your questions.

Edit: Opening an image with Memories doesn’t generate any warnings or errors at all in the browser console.

All right, we are getting closer.

Now, lets see, if we can get to the root of this. Please go to the network tab of the developer console. Keep it open.

  1. If possible enable (temporarily) the debug mode in your NC server (in the config/config.php).
  2. Navigate to the folder of the video. Do not yet open the video, just the folder.
  3. In the web developer console remove the history of past requests for better readability).
  4. Try to open the video.
  5. Go to the dev console again.

Do not forget: Disable the debug more again after investigation is done. It slows down your instance and you might leak some meta information (like exact versions of apps etc) about your instance if someone finds a bug in one of your apps. I consider the risk minimal but the performance will decrease for sure.

You will most probably see a few requests to be made. You will have to search for the corresponding request: If you click on one, you will get more details on it. There is also the full URL visible. You might be able to filter by HTML and keyword dav in the URL to simplify searching.

Is the request in question just a redirect 3xx or a real answer 2xx/4xx/5xx? If it is a redirect, where does it redirect to?
If it is a error page 4xx, there should be a HTML page served, that page can be viewed in the answer sub-tab. There is a stack trace. Have a look (or post it here).

Is the path of the file in question InstantUpload/DCIM/VID-20220430-WA0000.webm in the files of user ncp? Please check the path.

I suspect you have not disabled WebDAV or some “crazy” configuration of your server, right?

Right I have enabled Nextcloud debug mode. When I try to open the video in the app I can see that a GET request was made for filename "/index.php/remote.php/dav/files/ncp/InstantUpload/DCIM/VID-20220430-WA0000.webm". The response code to this request was 302 Found. I also got the following response header - Location: https://arctan.duckdns.org/index.php/apps/dashboard/.

Yes the file path seems to be a valid one. The exact path on the actual filesystem is /media/usb-hdd/nc-data/ncp/files/InstantUpload/DCIM/VID-20220430-WA0000.webm
(although I see that .../files/ncp/... in the Webdav URL translates to .../ncp/files/... in the filesystem).

Nope, no crazy configuration I’m afraid :slight_smile: . I’m using NextcloudPI and haven’t changed it that much from the default config. Webdav is enabled, I use it quite extensively and seems to be working elsewhere (i.e. outside of the Memories app),

Edit: I just realised that the Memories app is sending a GET request for "https://mydomainname/index.php/remote.php/dav/files/ncp/InstantUpload/DCIM/VID-20220430-WA0000.webm" . However “index.php” shouldn’t be in the URL. The correct URL is "https://mydomainname/remote.php/dav/files/ncp/InstantUpload/DCIM/VID-20220430-WA0000.webm" . If I put the unredacted correct URL into the web browser it downloads the file instead of redirecting to the Dashboard! Also Memories doesn’t appear to use WebDAV for accessing images, which is why that works! Do you think that the Memories app requesting an invalid URL for videos is a bug in the app as opposed to an issue with my server?

Good catch! I have overseen it myself.

Yes, that is a problem. If the path is no legit file (it is not as index.php is a file and no folder), it rewrites it internally to index.php which will evaluate the path and match with various cases (like core, apps, dashboard, login, etc). The remote interface is completely differently managed, so it should not pass through index.php.

My educated guess was that the video support is broken in the app by means of the wrong JS function to be called. There are multiple ones defined in the NPM package @nextcloud/router and I fear that the video support might be broken in the app. I think this issue is related. I will cross-post this topic here.

2 Likes

It was me that reported the Github issue :slight_smile:! Anyhow the app’s dev has now released a new version of the app (v3.10/v4.10 for different Nextcloud versions I think). And videos are now working fine for me! I’m not certain which commit it was that fixed the issue (but possibly this one).

Thank you for all your help, I’ve learnt a fair amount from it.

2 Likes