{"record":{"id":"995393911ed681ee","repo":"t8y2/dbx","slug":"failed-to-read-oracle-tns-file-s-w","errorCode":null,"errorMessage":"Failed to read Oracle TNS file %s: %w","messagePattern":"Failed to read Oracle TNS file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/oracle-go/tns.go","lineNumber":117,"sourceCode":"\treturn tnsNamesPath, nil\n}\n\nfunc readOracleTNSAliases(path string, visited map[string]bool, depth int) (map[string]string, error) {\n\tif depth > 8 {\n\t\treturn nil, fmt.Errorf(\"Oracle TNS include depth exceeds 8 files\")\n\t}\n\tabsolutePath, err := filepath.Abs(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Failed to resolve Oracle TNS file path: %w\", err)\n\t}\n\tif visited[absolutePath] {\n\t\treturn map[string]string{}, nil\n\t}\n\tvisited[absolutePath] = true\n\n\tfile, err := os.Open(absolutePath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Failed to read Oracle TNS file %s: %w\", absolutePath, err)\n\t}\n\tdefer file.Close()\n\n\taliases := make(map[string]string)\n\tvar currentAliases []string\n\tvar description strings.Builder\n\tdescriptionStarted := false\n\tparenthesisDepth := 0\n\tflush := func() {\n\t\tif len(currentAliases) == 0 {\n\t\t\treturn\n\t\t}\n\t\tvalue := strings.Join(strings.Fields(description.String()), \" \")\n\t\tif value != \"\" {\n\t\t\tfor _, alias := range currentAliases {\n\t\t\t\talias = strings.ToUpper(strings.TrimSpace(alias))\n\t\t\t\tif alias != \"\" {\n\t\t\t\t\taliases[alias] = value","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/oracle-go/tns.go#L99-L135","documentation":"readOracleTNSAliases opens the resolved absolute TNS file with os.Open; if that fails (file missing, permission denied, path is a directory), the OS error is wrapped in this message. This is the standard 'cannot read tnsnames.ora' failure for the Oracle driver.","triggerScenarios":"resolveOracleTNSAlias pointed at a TNS file path that does not exist, has wrong permissions, or is a directory — os.Open fails and the error is wrapped at tns.go:117.","commonSituations":"TNS_ADMIN or tnsNamesPath config pointing at a stale/nonexistent path; file mounted read-only or owned by another user in containers; typo in the configured TNS file path; file deleted after path discovery.","solutions":["Verify the file exists at the reported absolutePath (ls -l <path>) and fix the TNS path configuration","Check read permissions for the agent's user; chown/chmod as needed","Confirm TNS_ADMIN environment variable or the tnsNamesPath option points to the correct directory","In containers, ensure the TNS file is mounted into the image/pod","Read the wrapped %w error to distinguish not-found vs permission-denied"],"exampleFix":"// before: wrong path configured\npath := \"/etc/oracle/tnsnames.ora.bak\"\n\n// after: validate before use\npath := \"/etc/oracle/tnsnames.ora\"\nif _, err := os.Stat(path); err != nil {\n    log.Fatalf(\"TNS file missing: %v\", err)\n}","handlingStrategy":"validation","validationCode":"func tnsFileReadable(path string) error {\n    info, err := os.Stat(path)\n    if err != nil {\n        return fmt.Errorf(\"TNS file missing: %w\", err)\n    }\n    if info.IsDir() {\n        return fmt.Errorf(\"%s is a directory, not a file\", path)\n    }\n    f, err := os.Open(path)\n    if err != nil {\n        return fmt.Errorf(\"TNS file unreadable: %w\", err)\n    }\n    f.Close()\n    return nil\n}\n// run before resolveOracleTNSAlias","typeGuard":null,"tryCatchPattern":"aliases, err := resolveOracleTNSAlias(name)\nif err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) && errors.Is(perr.Err, fs.ErrNotExist) {\n        log.Printf(\"TNS file not found at %s; check TNS_ADMIN\", perr.Path)\n    } else if errors.As(err, &perr) && errors.Is(perr.Err, fs.ErrPermission) {\n        log.Printf(\"Permission denied reading %s\", perr.Path)\n    }\n    return err\n}","preventionTips":["Validate TNS_ADMIN / tnsNamesPath at agent startup with a stat check","Ensure the TNS file is baked into or mounted in container images","Use correct file ownership/permissions for the agent's service user","Fail fast at boot with a readable-file preflight check"],"tags":["oracle","tns","filesystem","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}