DrKLO/Telegram · error

Error writing.\n

Error message

Error writing.\n

What it means

In the merge (non-split) code path, the first fwrite call writes a 4-byte big-endian integer encoding the output packet length via int_to_char(). If fwrite returns fewer than 4 bytes, the output stream is broken (disk full, broken pipe, I/O error). The tool exits immediately with EXIT_FAILURE without closing fin/fout, which is a minor resource leak. This write encodes the length of the repacketized output packet that opus_repacketizer_out() just produced.

Source

Thrown at TMessagesProj/jni/opus/src/repacketizer_demo.c:165

         if (err!=OPUS_OK)
         {
            fprintf(stderr, "opus_repacketizer_cat() failed: %s\n", opus_strerror(err));
            break;
         }
      }
      nb_packets = i;

      if (eof)
         break;

      if (!split)
      {
         err = opus_repacketizer_out(rp, output_packet, MAX_PACKETOUT);
         if (err>0) {
            unsigned char int_field[4];
            int_to_char(err, int_field);
            if(fwrite(int_field, 1, 4, fout)!=4){
               fprintf(stderr, "Error writing.\n");
               return EXIT_FAILURE;
            }
            int_to_char(rng[nb_packets-1], int_field);
            if (fwrite(int_field, 1, 4, fout)!=4) {
               fprintf(stderr, "Error writing.\n");
               return EXIT_FAILURE;
            }
            if (fwrite(output_packet, 1, err, fout)!=(unsigned)err) {
               fprintf(stderr, "Error writing.\n");
               return EXIT_FAILURE;
            }
            /*fprintf(stderr, "out len = %d\n", err);*/
         } else {
            fprintf(stderr, "opus_repacketizer_out() failed: %s\n", opus_strerror(err));
         }
      } else {
         int nb_frames = opus_repacketizer_get_nb_frames(rp);
         for (i=0;i<nb_frames;i++)

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Check available disk space before running: `df -h <output_dir>`.
  2. If piping output, ensure the reader consumes all data or handle SIGPIPE.
  3. Write to a local filesystem instead of network mounts for large outputs.
Defensive patterns

Strategy: validation

Validate before calling

// Check disk space and output writability before processing
#include <sys/statvfs.h>
int check_disk_space(const char *path, unsigned long min_bytes) {
    struct statvfs vfs;
    if (statvfs(path, &vfs) != 0) return -1;
    return (vfs.f_bavail * vfs.f_bsize >= min_bytes) ? 0 : -1;
}

Prevention

When it happens

Trigger: Disk full; output redirected to a pipe whose reader has exited (SIGPIPE suppressed); network filesystem write failure; removable media ejected mid-write.

Common situations: Writing to a full /tmp partition; piping output to `head` which exits early; NFS timeout; running in a CI environment with limited disk quota.

Related errors


AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14). Data as JSON: /api/errors/12031f718ac27631. Report an issue: GitHub.