Yalantis/uCrop · error · CImgArgumentException

load_dcraw_external(): Specified filename is (null) or does

Error message

load_dcraw_external(): Specified filename is (null) or does not exist.

What it means

load_dcraw_external() loads a RAW camera file (CR2, NEF, DNG, ...) by delegating to the external 'dcraw' tool. It validates the argument first: if filename is null or no such regular file exists (cimg::is_file), it throws this CImgArgumentException before invoking dcraw.

Source

Thrown at ucrop/src/main/jni/CImg.h:59962

                              filename);
      }
      load_pnm(filename_tmp);
      std::remove(filename_tmp);
      return *this;
    }

    //! Load image from a .pdf file \newinstance.
    static CImg<T> get_load_pdf_external(const char *const filename, const unsigned int resolution=400) {
      return CImg<T>().load_pdf_external(filename,resolution);
    }

    //! Load image from a RAW Color Camera file, using external tool 'dcraw'.
    /**
       \param filename Filename, as a C-string.
    **/
    CImg<T>& load_dcraw_external(const char *const filename) {
      if (!filename || !cimg::is_file(filename))
        throw CImgArgumentException(_cimg_instance
                                    "load_dcraw_external(): Specified filename is (null) or does not exist.",
                                    cimg_instance);
      CImg<charT> command(1024), filename_tmp(256);
      const CImg<charT> s_filename = CImg<charT>::string(filename)._system_strescape();
#if cimg_OS==1
      cimg_snprintf(command,command._width,"%s -w -4 -c \"%s\"",
                    cimg::dcraw_path(),s_filename.data());
      std::FILE *file = popen(command,"r");
      if (file) {
        const unsigned int omode = cimg::exception_mode();
        cimg::exception_mode(0);
        try { load_pnm(file); } catch (...) {
          pclose(file);
          cimg::exception_mode(omode);
          throw CImgIOException(_cimg_instance
                                "load_dcraw_external(): Failed to load file '%s' with external command 'dcraw'.",
                                cimg_instance,
                                filename);

View on GitHub (pinned to f788b534b4)

Solutions

  1. Stat the path first and fail with your own clear error if it is not an existing regular file.
  2. Log the absolute path (realpath) being passed and fix how it is constructed.
  3. Check case-sensitive filesystem expectations and normalize the extension.
  4. Fix the upstream source (upload, DB record, config) so the RAW file is present before loading.
  5. If dcraw is optional, skip gracefully when the file is absent instead of calling the loader.

Example fix

// before
img.load_dcraw_external(rawPath); // may be null/stale
// after
if (!rawPath || !cimg::is_file(rawPath))
  throw std::invalid_argument("RAW file not found: " + std::string(rawPath?rawPath:"(null)"));
img.load_dcraw_external(rawPath);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!path || !cimg::is_file(path))
  throw std::invalid_argument("RAW path null or file missing");

Type guard

bool isRawFilePresent(const char* p){ return p && cimg::is_file(p); }

Try / catch

try { img.load_dcraw_external(path); }
catch (CImgArgumentException& e) { log("missing RAW file"); }

Prevention

When it happens

Trigger: Calling CImg<T>::load_dcraw_external(nullptr) or with a path that does not exist / is a directory / is a broken symlink; also when a photo-ingest pipeline passes a filename whose file was moved or renamed before loading.

Common situations: Card-ingest code building paths from filenames that were not actually copied; case-sensitivity mismatches (.CR2 vs .cr2) on Linux; empty database/config field for the RAW path; relative path with unexpected working directory.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/92d24a94a3e50c54. Report an issue: GitHub.