{"record":{"id":"d9a06219a08a0e3d","repo":"OpenNHP/opennhp","slug":"file-not-found-w","errorCode":null,"errorMessage":"file not found: %w","messagePattern":"file not found: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nhp/utils/crypto.go","lineNumber":127,"sourceCode":"func GenerateRsaKey(bits int) (string, string) {\n\t// Generate private key.\n\tprivateKey, err := rsa.GenerateKey(rand.Reader, bits)\n\tif err != nil {\n\t\treturn \"\", \"\"\n\t}\n\tpivKey := x509.MarshalPKCS1PrivateKey(privateKey)\n\tpubKey := x509.MarshalPKCS1PublicKey(&privateKey.PublicKey)\n\n\treturn base64.StdEncoding.EncodeToString(pivKey), base64.StdEncoding.EncodeToString(pubKey)\n}\n\n// Md5sum computes MD5 checksum for file integrity verification (not cryptographic security)\n//\n//nolint:gosec // G401: MD5 used for file integrity checksums, not for cryptographic security\nfunc Md5sum(fullFilePath string) (string, error) {\n\tfileInfo, err := os.Stat(fullFilePath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"file not found: %w\", err)\n\t}\n\n\tif !fileInfo.Mode().IsRegular() {\n\t\treturn \"\", fmt.Errorf(\"path is not a regular file\")\n\t}\n\n\tfile, err := os.Open(fullFilePath) //nolint:gosec // G304: Path validated by os.Stat above\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to open file: %w\", err)\n\t}\n\tdefer file.Close()\n\n\thasher := md5.New()\n\n\tif _, err := io.Copy(hasher, file); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to read file content: %w\", err)\n\t}\n","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/nhp/utils/crypto.go#L109-L145","documentation":"Md5sum computes an MD5 checksum of a file for integrity verification. Before reading, it calls os.Stat on the given path; if Stat fails the file cannot be located or accessed, and the underlying error is wrapped as \"file not found: %w\". This gives callers a single descriptive error whether the path is missing, is a permission issue, or has a bad parent directory.","triggerScenarios":"Calling utils.Md5sum with a path that does not exist, a dangling symlink, a typo in the filename, or a path whose parent directory is inaccessible so os.Stat returns an error.","commonSituations":"TA service registration passes a plugin/TA file path from config that was moved or never deployed; relative path used while the process runs from a different working directory; case-sensitivity mismatch on Linux filesystems.","solutions":["Verify the path exists: run ls -l on the exact fullFilePath used by the caller","Fix the configured path (config file or hardcoded value) to the correct absolute path","Check that the process user has search permission on every directory component of the path","If the path should be relative, set the correct working directory or convert it to an absolute path"],"exampleFix":"// before\nsum, err := utils.Md5sum(cfg.TaFile)\n// after\nif _, err := os.Stat(cfg.TaFile); err != nil {\n    log.Error(\"TA file %q not accessible: %v\", cfg.TaFile, err)\n    return err\n}\nsum, err := utils.Md5sum(cfg.TaFile)","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(p); err != nil || !info.Mode().IsRegular() { return err }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve config paths to absolute at load time"],"tags":["go","filesystem","md5","file"],"backgroundTag":"file-not-found","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}