DrKLO/Telegram · error

%s: can't open %s

Error message

%s: can't open %s

What it means

cjpeg opens the positional input file with fopen(path, READ_BINARY). If fopen returns NULL (file missing, path wrong, permission denied, or unreadable), this message prints and the process exits with EXIT_FAILURE. The %s is the offending input path.

Source

Thrown at TMessagesProj/jni/mozjpeg/cjpeg.c:742

      if (file_index != argc - 1) {
        fprintf(stderr, "%s: must name one input and one output file\n",
                progname);
        usage();
      }
    }
  }
#else
  /* Unix style: expect zero or one file name */
  if (file_index < argc - 1) {
    fprintf(stderr, "%s: only one input file\n", progname);
    usage();
  }
#endif /* TWO_FILE_COMMANDLINE */

  /* Open the input file. */
  if (file_index < argc) {
    if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
      fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
      exit(EXIT_FAILURE);
    }
  } else {
    /* default input file is stdin */
    input_file = read_stdin();
  }

  /* Open the output file. */
  if (outfilename != NULL) {
    if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
      fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
      exit(EXIT_FAILURE);
    }
  } else if (!memdst) {
    /* default output file is stdout */
    output_file = write_stdout();
  }

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Verify the path exists and is readable: ls -l <path> and test -r <path> before invoking cjpeg.
  2. Use absolute paths to avoid working-directory drift.
  3. Check file permissions and ownership; ensure the invoking process has read access.
  4. Confirm the path is a regular file, not a directory.

Example fix

# before: wrong/missing path
cjpeg /wrong/dir/in.ppm out.jpg
# after
cjpeg "$(pwd)/in.ppm" out.jpg
Defensive patterns

Strategy: validation

Validate before calling

#!/bin/sh
IN="$1"
[ -n "$IN" ] || { echo 'no input file given' >&2; exit 1; }
[ -f "$IN" ] || { echo "not a regular file: $IN" >&2; exit 1; }
[ -r "$IN" ] || { echo "not readable: $IN" >&2; exit 1; }
cjpeg "$IN" out.jpg

Type guard

// n/a: filesystem precondition check in the caller.

Try / catch

if ! cjpeg "$IN" out.jpg 2>/tmp/e; then
  grep -q "can't open" /tmp/e && { echo "input file missing/unreadable: $IN" >&2; ls -l "$IN"; exit 1; }
fi

Prevention

When it happens

Trigger: The input file path does not exist, is not readable by the current user, is a directory, or the path is malformed. Triggered when file_index < argc and fopen fails.

Common situations: Wrong working directory / relative path; typos in the path; permission issues on mounted volumes or Android storage paths; the file was deleted between staging and invocation; a glob that did not expand.

Related errors


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