DrKLO/Telegram · error

: missing argument for trellis-dc-ver-weight

Error message

%s: missing argument for trellis-dc-ver-weight

What it means

The mozjpeg-specific -trellis-dc-ver-weight switch requires a floating-point numeric argument (it sets JFLOAT_TRELLIS_DELTA_DC_WEIGHT). When the switch is the last token on the command line, the ++argn >= argc check fires because there is no following token to consume, and cjpeg prints this message and calls usage().

Solutions

  1. Append the numeric weight value immediately after the switch, e.g. -trellis-dc-ver-weight 1.5.
  2. In script-generated command lines, guard that the value variable is non-empty before emitting the flag.
  3. Validate the value parses as a float before passing it, since a non-numeric next token would be consumed silently by atof.

Example fix

# before
cjpeg -trellis-dc-ver-weight input.ppm > out.jpg
# after
cjpeg -trellis-dc-ver-weight 1.5 input.ppm > out.jpg
Defensive patterns

Strategy: validation

Validate before calling

#!/bin/sh
# Ensure a value follows -trellis-dc-ver-weight and parses as float
is_float() { case "$1" in ''|*[!0-9.]*) return 1;; *) return 0;; esac; }
argv=()
while [ $# -gt 0 ]; do
  case "$1" in
    -trellis-dc-ver-weight)
      shift
      if [ $# -eq 0 ] || ! is_float "$1"; then
        echo 'missing/invalid value for -trellis-dc-ver-weight' >&2; exit 1
      fi
      argv+=(-trellis-dc-ver-weight "$1");;
    *) argv+=("$1");;
  esac
  shift
done
set -- "${argv[@]}"
cjpeg "$@"

Type guard

// n/a: CLI argv validation belongs in the shell wrapper, not a typed guard.

Try / catch

# No in-process catch; validate argv then check subprocess exit code:
if ! cjpeg -trellis-dc-ver-weight "$W" in.ppm > out.jpg 2>/tmp/e; then
  grep -q 'missing argument for trellis-dc-ver-weight' /tmp/e && W=1.5  # supply default and retry
  exit 1
fi

Prevention

When it happens

Trigger: Invoking cjpeg with -trellis-dc-ver-weight as the final argument, or with no token after it: cjpeg ... -trellis-dc-ver-weight (end of argv). The ++argn >= argc guard trips before atof is reached.

Common situations: Shell scripts that append flags dynamically and drop the trailing value due to a quoting/unset-variable bug; copy-pasting a partial command line; flags generated from a config file where the value field is empty.

Related errors


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

Appendix: source

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

      if (val < 0 || val > 100)
        usage();
      cinfo->smoothing_factor = val;

    } else if (keymatch(arg, "targa", 1)) {
      /* Input file is Targa format. */
      is_targa = TRUE;

    } else if (keymatch(arg, "notrellis-dc", 11)) {
      /* disable trellis quantization */
      jpeg_c_set_bool_param(cinfo, JBOOLEAN_TRELLIS_QUANT_DC, FALSE);
      
    } else if (keymatch(arg, "notrellis", 1)) {
      /* disable trellis quantization */
      jpeg_c_set_bool_param(cinfo, JBOOLEAN_TRELLIS_QUANT, FALSE);
      
    } else if (keymatch(arg, "trellis-dc-ver-weight", 12)) {
      if (++argn >= argc) {      /* advance to next argument */
        fprintf(stderr, "%s: missing argument for trellis-dc-ver-weight\n", progname);
        usage();
      }
      jpeg_c_set_float_param(cinfo, JFLOAT_TRELLIS_DELTA_DC_WEIGHT, atof(argv[argn]));
      
    } else if (keymatch(arg, "trellis-dc", 9)) {
      /* enable DC trellis quantization */
      jpeg_c_set_bool_param(cinfo, JBOOLEAN_TRELLIS_QUANT_DC, TRUE);
      
    } else if (keymatch(arg, "tune-psnr", 6)) {
      jpeg_c_set_int_param(cinfo, JINT_BASE_QUANT_TBL_IDX, 1);
      jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE1, 9.0);
      jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE2, 0.0);
      jpeg_c_set_bool_param(cinfo, JBOOLEAN_USE_LAMBDA_WEIGHT_TBL, FALSE);
      jpeg_set_quality(cinfo, 75, TRUE);
      
    } else if (keymatch(arg, "tune-ssim", 6)) {
      jpeg_c_set_int_param(cinfo, JINT_BASE_QUANT_TBL_IDX, 1);
      jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE1, 11.5);

View on GitHub (pinned to 45ab8f4308)