Problem/Motivation
AudioGeneratorBatch::resolveFilename() builds the output filename from a token template (e.g [node:title]_[node:nid]) with no length cap. The "Filename template" setting accepts arbitrary tokens, and nothing bounds the length of the token-substituted value — a long node title is one way to trigger this, but any token (or combination of tokens) that resolves to a long string hits the same problem. An overly long resolved filename overflows two different limits:
1. Filesystem: the sanitized name.ext alone can exceed the ~255-byte-per-path-component limit most Linux filesystems (ext4 etc.) enforce, so fopen() in mergeChunks() fails outright: Failed to merge audio chunks: Could not open output file for writing: /var/www/html/web/sites/default/files/audio/<long-name>_28023.mp3
2. Database: even once the filename itself is within the filesystem limit, it's stored as part of the file_managed.uri column when the File entity is saved — and that column holds the full URI (scheme://directory/filename), also capped at 255 bytes. A filename close to 255 bytes plus the public://audio/ (or a longer private://…) prefix overflows the column:
Drupal\Core\Entity\EntityStorageException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'uri' at row 1
Both failures share the same root cause — no length cap on the token-resolved filename — and surface as unrelated-looking, misleading errors (a disk/permissions-looking error in one case, a raw SQL error in the other) instead of a clear "filename too long" message.
Steps to reproduce
1. Set the "Filename template" setting to include a token whose resolved value is long (e.g. [node:title]_[node:nid] on a node with a long title).
2. Generate audio for that node.
3. Depending on exact lengths involved, either the merge step fails to open the output file, or it writes the file but then fails to save the File entity with the SQL error above.
Proposed resolution
In resolveFilename(), truncate the sanitized, token-substituted base name to a safe length before appending the extension — capped below the 255-byte filesystem limit by a margin (e.g. 20 bytes) that reserves room for the storage directory's scheme/path prefix (public://audio/ or a longer private:// path), since the resulting filename is later stored as part of the file_managed.uri column. This bounds the filename regardless of which token(s) the site's filename template uses, and keeps both the on-disk filename and the stored URI within their respective limits.
Issue fork ai_audio_generator-3613641
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
nnevill