{"record":{"id":"92d24a94a3e50c54","repo":"Yalantis/uCrop","slug":"load-dcraw-external-specified-filename-is-null","errorCode":null,"errorMessage":"load_dcraw_external(): Specified filename is (null) or does not exist.","messagePattern":"load_dcraw_external\\(\\): Specified filename is \\(null\\) or does not exist\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":59962,"sourceCode":"                              filename);\n      }\n      load_pnm(filename_tmp);\n      std::remove(filename_tmp);\n      return *this;\n    }\n\n    //! Load image from a .pdf file \\newinstance.\n    static CImg<T> get_load_pdf_external(const char *const filename, const unsigned int resolution=400) {\n      return CImg<T>().load_pdf_external(filename,resolution);\n    }\n\n    //! Load image from a RAW Color Camera file, using external tool 'dcraw'.\n    /**\n       \\param filename Filename, as a C-string.\n    **/\n    CImg<T>& load_dcraw_external(const char *const filename) {\n      if (!filename || !cimg::is_file(filename))\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_dcraw_external(): Specified filename is (null) or does not exist.\",\n                                    cimg_instance);\n      CImg<charT> command(1024), filename_tmp(256);\n      const CImg<charT> s_filename = CImg<charT>::string(filename)._system_strescape();\n#if cimg_OS==1\n      cimg_snprintf(command,command._width,\"%s -w -4 -c \\\"%s\\\"\",\n                    cimg::dcraw_path(),s_filename.data());\n      std::FILE *file = popen(command,\"r\");\n      if (file) {\n        const unsigned int omode = cimg::exception_mode();\n        cimg::exception_mode(0);\n        try { load_pnm(file); } catch (...) {\n          pclose(file);\n          cimg::exception_mode(omode);\n          throw CImgIOException(_cimg_instance\n                                \"load_dcraw_external(): Failed to load file '%s' with external command 'dcraw'.\",\n                                cimg_instance,\n                                filename);","sourceCodeStart":59944,"sourceCodeEnd":59980,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L59944-L59980","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Stat the path first and fail with your own clear error if it is not an existing regular file.","Log the absolute path (realpath) being passed and fix how it is constructed.","Check case-sensitive filesystem expectations and normalize the extension.","Fix the upstream source (upload, DB record, config) so the RAW file is present before loading.","If dcraw is optional, skip gracefully when the file is absent instead of calling the loader."],"exampleFix":"// before\nimg.load_dcraw_external(rawPath); // may be null/stale\n// after\nif (!rawPath || !cimg::is_file(rawPath))\n  throw std::invalid_argument(\"RAW file not found: \" + std::string(rawPath?rawPath:\"(null)\"));\nimg.load_dcraw_external(rawPath);","handlingStrategy":"type-guard","validationCode":"if (!path || !cimg::is_file(path))\n  throw std::invalid_argument(\"RAW path null or file missing\");","typeGuard":"bool isRawFilePresent(const char* p){ return p && cimg::is_file(p); }","tryCatchPattern":"try { img.load_dcraw_external(path); }\ncatch (CImgArgumentException& e) { log(\"missing RAW file\"); }","preventionTips":["Verify ingest/copy completed before loading RAW files","Normalize extension case for Linux filesystems","Resolve relative paths against an explicit base directory","Validate path fields at config-load time"],"tags":["dcraw","raw-image","argument-validation","file","cimg"],"backgroundTag":"file-not-found","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}