[Bug] Nil assertion failed (NilAssertionError)
Describe the bug
Some videos randomly don't play at all and return "Nil assertion failed (NilAssertionError)".
Steps to Reproduce
- Open this video on an invidious instance https://www.youtube.com/watch?v=0NRrsrYmRuE
- See the screenshot
Logs
Title: Nil assertion failed (NilAssertionError)
Date: 2025-06-04T17:58:39Z
Route: /watch?v=0NRrsrYmRuE
Version: 2025.05.17-f07859e @ (HEAD detached at v2.20250517.0)
Backtrace
Nil assertion failed (NilAssertionError)
from /usr/share/crystal/src/nil.cr:113:7 in 'not_nil!'
from /usr/share/crystal/src/nil.cr:109:3 in 'not_nil!'
from src/invidious/http_server/utils.cr:12:24 in 'proxy_video_url'
from src/invidious/routes/watch.cr:128:32 in 'handle'
from lib/kemal/src/kemal/route.cr:13:9 in '->'
from src/invidious/helpers/handlers.cr:31:37 in 'call'
from /usr/share/crystal/src/http/server/handler.cr:30:7 in 'call'
from /usr/share/crystal/src/http/server/handler.cr:30:7 in 'call_next'
from lib/kemal/src/kemal/filter_handler.cr:21:7 in 'call'
from /usr/share/crystal/src/http/server/handler.cr:30:7 in 'call'
from /usr/share/crystal/src/http/server/handler.cr:30:7 in 'call_next'
from src/invidious/helpers/handlers.cr:95:12 in 'call'
from /usr/share/crystal/src/http/server/handler.cr:30:7 in 'call'
from /usr/share/crystal/src/http/server/handler.cr:30:7 in 'call'
from /usr/share/crystal/src/http/server/handler.cr:30:7 in 'call_next'
from src/ext/kemal_static_file_handler.cr:106:14 in 'call'
from /usr/share/crystal/src/http/server/handler.cr:30:7 in 'call'
from /usr/share/crystal/src/http/server/handler.cr:30:7 in 'call'
from /usr/share/crystal/src/http/server/handler.cr:30:7 in 'call'
from /usr/share/crystal/src/http/server/request_processor.cr:51:11 in 'handle_client'
from /usr/share/crystal/src/fiber.cr:143:11 in 'run'
from ???
Screenshots
Additional context
I'm using a localhost instance to play them with the docker image. Could it be something related to #5322 ?
I have this occuring also on some videos again recently.
Just out of interest, are u using inv-sig-helper aswell or companion?
If inv-sig-helper, and not many reports come in here, i guess it's time to switch to companion.
I see u are using a slightly older version than the current one, and there have been some changes made in parser since.
I'n my case i hadn't updated aswell, just did, and there's no issue anymore. The video u provided did also throw this error, now while updated it does''t anymore.
We should update first before posting here, especially when creating a issue, my bad aswell.
I suggest u update aswell, and perhaps close this issue if u observe it working again.
Oh right, i'm not using docker. This is the update i'm talking about: https://github.com/iv-org/invidious/commit/df8839d1f018644afecb15e144f228d811708f8f
Perhaps u could try to change image: quay.io/invidious/invidious:latest to image: quay.io/invidious/invidious:master in your docker compose file.
EDIT: Oops! Sorry about the close completely misread the issue 😅
Duplicate of #5307
I'll probably be publishing a new stable release with the fix soon
Here's a patch to fix this.
Its caused by Invidious not discarding the unsupported SABR format data during parsing when both the fallback attempts fails to retrieve valid formats for DASH. So attempts to read the eventual adaptive_formats attribute on the parsed Video object would always yield the the data for the sabr formats, which has their url attribute set to an empty string.
Patch
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index 348a0a66..dafa6b60 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -29,6 +29,11 @@ struct Video
@[DB::Field(ignore: true)]
property description : String?
+ # DB::Field(ignore: ...) is also used to ignore an instance value as apart of our patch of
+ # DB::Serializable to also generate a constructor that takes in the defined properties as arguments
+ @[DB::Field(ignore: true)]
+ @streams_has_valid_link : Bool? = nil
+
module JSONConverter
def self.from_rs(rs)
JSON.parse(rs.read(String)).as_h
@@ -103,7 +108,7 @@ struct Video
end
def adaptive_fmts : Array(Hash(String, JSON::Any))
- if formats = info.dig?("streamingData", "adaptiveFormats")
+ if ((formats = info.dig?("streamingData", "adaptiveFormats")) && streams_has_link?(formats))
return formats
.as_a.map(&.as_h)
.sort_by! { |f| f["width"]?.try &.as_i || f["audioTrack"]?.try { |a| a["audioIsDefault"]?.try { |v| v.as_bool ? -1 : 0 } } || 0 }
@@ -120,6 +125,12 @@ struct Video
adaptive_fmts.select &.["mimeType"]?.try &.as_s.starts_with?("audio")
end
+ private def streams_has_link?(formats)
+ streams_has_valid_link = @streams_has_valid_link
+ return streams_has_valid_link if !(streams_has_valid_link.nil?)
+ return @streams_has_valid_link ||= !(formats.dig?(0, "url").try(&.as_s.empty?) || false)
+ end
+
# Misc. methods
def storyboards
This will allow the /watch page to load without an error but the video will almost certainly be unplayable.
Oh right, i'm not using docker. This is the update i'm talking about: df8839d
Perhaps u could try to change image: quay.io/invidious/invidious:latest to image: quay.io/invidious/invidious:master in your docker compose file.
I want to correct myself here, apparently the issue is back on the video as provided in first post. Yesterday after updating it worked, aswell as other videos that didn't. I made the assumption the update fixed it.
My instance exit node rotates ip every hour, so probably it is some A/B testing, hence why it worked after the update on a specific ip, and now doesn't anymore.
Edit: 100% confirmed, /watch?v=0NRrsrYmRuE working on some ip's, while 'nil assertion...' on others
Hello, is a fix already available for people using containers? I just tried to install invidious locally and had the same issue, but not on all videos.
Hello, is a fix already available for people using containers? I just tried to install invidious locally and had the same issue, but not on all videos.
I am on the latest Docker versions and have this issue, so I'd say not quite yet.
Please only comment if you have something new to bring on.
Don't know if this is of help, but I found that the problem always shows when I try to watch a music video. Other videos are working fine.
Don't know if this is of help, but I found that the problem always shows when I try to watch a music video. Other videos are working fine.
I have found that this is a common theme, but other videos with a "static" image and audio in the background can also be affected.
This will allow the
/watchpage to load without an error but the video will almost certainly be unplayable.
Working fine for me for multiple affected videos
Steps for folks landing here who aren't as confident with Git/Docker:
- Copy the patch content from syeopite's comment and paste it in some local file, e.g.
patchfile.patch. cdto the repository root, thengit apply /path/to/patchfile.patch- If you followed the Docker steps from the docs, you'll need to update your
docker-compose.ymlto build locally. Underinviduous:remove theimage:line and replace it withbuild:, as in the dev config docker compose up --build
i am using the latest docker image, when applying the patch the second hunk fails, since the signature for my adaptive_fmts is different
def adaptive_fmts
return @adaptive_fmts.as(Array(Hash(String, JSON::Any))) if @adaptive_fmts
instead of expected:
def adaptive_fmts : Array(Hash(String, JSON::Any))
the image I am using is image: quay.io/invidious/invidious:latest
This will allow the
/watchpage to load without an error but the video will almost certainly be unplayable.Working fine for me for multiple affected videos
Steps for folks landing here who aren't as confident with Git/Docker:
- Copy the patch content from syeopite's comment and paste it in some local file, e.g.
patchfile.patch.cdto the repository root, thengit apply /path/to/patchfile.patch- If you followed the Docker steps from the docs, you'll need to update your
docker-compose.ymlto build locally. Underinviduous:remove theimage:line and replace it withbuild:, as in the dev configdocker compose up --build
syeopite's patch makes the video playable by switching the video over to "medium", but it's not really a true fix as it makes the "medium" quality version playable when the adaptive dash version (1080p+) should be playing, but it's better than nothing, i.e. better than the nilassertionerror.
Here's a patch to fix this.
Its caused by Invidious not discarding the unsupported SABR format data during parsing when both the fallback attempts fails to retrieve valid formats for DASH. So attempts to read the eventual
adaptive_formatsattribute on the parsedVideoobject would always yield the the data for the sabr formats, which has theirurlattribute set to an empty string.Patch This will allow the
/watchpage to load without an error but the video will almost certainly be unplayable.
I just updated my Invidious install and I'm regretting it already, now it no longer works. I'm also getting the "Nil assertion failed (NilAssertionError)" - with and without the patch. May be a different problem causing similar error messages?
I had to enable an automatic redirector in my browser, so I could watch videos again (by redirecting to the YouTube /watch URL).
Is invidious still in development? Is there any timeline for the official docker image to be fixed?
This will most likely be solved when Invidious companion will be the default install method: #5266.
And the maintainers work on their free time so it's normal to have some delay in bug fixes.