DrKLO/Telegram · error

%s: can't open %s

Error message

%s: can't open %s

What it means

djpeg's -map switch loads an external color map (for color quantization) from a file. Under QUANT_2PASS_SUPPORTED it opens the file with fopen(path, READ_BINARY); if fopen returns NULL it prints this message and exits EXIT_FAILURE. The %s is the map file path.

Source

Thrown at TMessagesProj/jni/mozjpeg/djpeg.c:330

      cinfo->out_color_space = JCS_RGB565;

    } else if (keymatch(arg, "icc", 1)) {
      /* Set ICC filename. */
      if (++argn >= argc)       /* advance to next argument */
        usage();
      icc_filename = argv[argn];
      jpeg_save_markers(cinfo, JPEG_APP0 + 2, 0xFFFF);

    } else if (keymatch(arg, "map", 3)) {
      /* Quantize to a color map taken from an input file. */
      if (++argn >= argc)       /* advance to next argument */
        usage();
      if (for_real) {           /* too expensive to do twice! */
#ifdef QUANT_2PASS_SUPPORTED    /* otherwise can't quantize to supplied map */
        FILE *mapfile;

        if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) {
          fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
          exit(EXIT_FAILURE);
        }
        read_color_map(cinfo, mapfile);
        fclose(mapfile);
        cinfo->quantize_colors = TRUE;
#else
        ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif
      }

    } else if (keymatch(arg, "maxmemory", 3)) {
      /* Maximum memory in Kb (or Mb with 'm'). */
      long lval;
      char ch = 'x';

      if (++argn >= argc)       /* advance to next argument */
        usage();
      if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Verify the map file exists and is readable before invoking djpeg.
  2. Use an absolute path and confirm the file is in the format read_color_map expects.
  3. If you do not need color quantization to a supplied map, drop the -map switch and let djpeg compute one with -colors / -onepass / -two_pass.

Example fix

# before: map path missing
djpeg -map /wrong/colormap in.jpg out.ppm
# after
djpeg -map "$(pwd)/colormap.map" in.jpg out.ppm
Defensive patterns

Strategy: validation

Validate before calling

#!/bin/sh
MAP="$1"
[ -f "$MAP" ] && [ -r "$MAP" ] || { echo "map file missing/unreadable: $MAP" >&2; exit 1; }
djpeg -map "$MAP" in.jpg out.ppm  # requires QUANT_2PASS_SUPPORTED in this build

Type guard

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

Try / catch

if ! djpeg -map "$MAP" in.jpg out.ppm 2>/tmp/e; then
  grep -q "can't open" /tmp/e && { echo "map file missing/unreadable: $MAP" >&2; exit 1; }
fi

Prevention

When it happens

Trigger: Passing -map <file> (only honored when for_real is true) where the map file does not exist, is unreadable, or is a directory.

Common situations: Wrong/relative map file path; missing colormap asset; permission issues; passing a PPM/JPEG by mistake instead of a colormap file expected by read_color_map.

Related errors


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