{"record":{"id":"c4e05e899617c383","repo":"Yalantis/uCrop","slug":"load-dcraw-external-failed-to-load-file-s-wi","errorCode":null,"errorMessage":"load_dcraw_external(): Failed to load file '%s' with external command 'dcraw'.","messagePattern":"load_dcraw_external\\(\\): Failed to load file '(.+?)' with external command 'dcraw'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":59977,"sourceCode":"    **/\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);\n        }\n        pclose(file);\n        return *this;\n      }\n#endif\n      do {\n        cimg_snprintf(filename_tmp,filename_tmp._width,\"%s%c%s.ppm\",\n                      cimg::temporary_path(),cimg_file_separator,cimg::filenamerand());\n      } while (cimg::path_exists(filename_tmp));\n      cimg_snprintf(command,command._width,\"\\\"%s\\\" -w -4 -c \\\"%s\\\" > \\\"%s\\\"\",\n                    cimg::dcraw_path(),s_filename.data(),CImg<charT>::string(filename_tmp)._system_strescape().data());\n      cimg::system(command,cimg::dcraw_path());\n      if (!cimg::path_exists(filename_tmp)) {\n        cimg::fclose(cimg::fopen(filename,\"r\"));\n        throw CImgIOException(_cimg_instance","sourceCodeStart":59959,"sourceCodeEnd":59995,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L59959-L59995","documentation":"On Unix, load_dcraw_external() opens a pipe 'dcraw -w -4 -c \"<file>\"' with popen() and decodes the PNM stream from dcraw's stdout. If load_pnm throws while reading that stream, this CImgIOException is thrown: dcraw ran but its output could not be parsed as an image.","triggerScenarios":"Calling load_dcraw_external(filename) on Unix where dcraw starts but emits an invalid or empty PNM stream — dcraw not really installed (shell printed 'command not found' into the pipe), unsupported camera RAW format, corrupted RAW file, or dcraw erroring mid-conversion.","commonSituations":"dcraw missing on the deployment machine so popen succeeds but the pipe yields only a shell error message; new camera formats dcraw does not support (project dormant — LibRaw is maintained instead); truncated RAW transfers from memory cards.","solutions":["Verify dcraw exists: run 'dcraw' in the same environment; install it (or switch to LibRaw) if missing.","Run 'dcraw -w -4 -c file.CR2 > out.ppm' manually to see dcraw's actual error message.","Check the RAW file is complete and from a supported camera (update dcraw or use LibRaw for newer models).","Confirm the process user can read the RAW file.","Convert the RAW yourself with LibRaw/dcraw to PPM/TIFF and load it with CImg::load(), giving you direct access to the tool's exit status."],"exampleFix":"// before\nimg.load_dcraw_external(\"IMG_0001.CR2\");\n// after\ntry { img.load_dcraw_external(\"IMG_0001.CR2\"); }\ncatch (CImgIOException&) {\n  if (cimg::system(\"dcraw -w -4 -c IMG_0001.CR2 > IMG_0001.ppm\"))\n    throw std::runtime_error(\"dcraw failed/missing for IMG_0001.CR2\");\n  img.load(\"IMG_0001.ppm\");\n}","handlingStrategy":"try-catch","validationCode":"if (!cimg::is_file(path)) throw std::invalid_argument(\"RAW missing\");\nif (cimg::system(\"dcraw --version\",\"dcraw\")!=0 && cimg::system(\"dcraw\",\"dcraw\")!=0)\n  throw std::runtime_error(\"dcraw not installed\");","typeGuard":"bool dcrawAvailable(){ return cimg::system(\"dcraw\",\"dcraw\")==0 || cimg::system(\"dcraw -V\",\"dcraw\")==0; }","tryCatchPattern":"try { img.load_dcraw_external(path); }\ncatch (CImgIOException& e) {\n  // decode yourself to get dcraw's real exit status\n  if (cimg::system(\"dcraw -w -4 -c <file> > out.ppm\"))\n    throw std::runtime_error(\"dcraw failed or unsupported RAW format\");\n  img.load(\"out.ppm\");\n}","preventionTips":["Install dcraw (or migrate to LibRaw) in deployment images","Check camera support for newer RAW formats","Verify RAW file integrity after transfers","Avoid popen-based external loads where exit status matters — render to a file instead"],"tags":["dcraw","raw-image","pnm","external-tool","cimg"],"backgroundTag":"command-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"}