{"record":{"id":"8bd1a9a7cce36328","repo":"kataras/iris","slug":"directorypath-is-empty","errorCode":null,"errorMessage":"directoryPath is empty","messagePattern":"directoryPath is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sessions/sessiondb/badger/database.go","lineNumber":45,"sourceCode":"\t// it's initialized at `New` or `NewFromDB`.\n\t// Can be used to get stats.\n\tService *badger.DB\n\tlogger  *golog.Logger\n\n\tclosed uint32 // if 1 is closed.\n}\n\nvar _ sessions.Database = (*Database)(nil)\n\n// New creates and returns a new badger(key-value file-based) storage\n// instance based on the \"directoryPath\".\n// DirectoryPath should is the directory which the badger database will store the sessions,\n// i.e ./sessions\n//\n// It will remove any old session files.\nfunc New(directoryPath string) (*Database, error) {\n\tif directoryPath == \"\" {\n\t\treturn nil, errors.New(\"directoryPath is empty\")\n\t}\n\n\tlindex := directoryPath[len(directoryPath)-1]\n\tif lindex != os.PathSeparator && lindex != '/' {\n\t\tdirectoryPath += string(os.PathSeparator)\n\t}\n\t// create directories if necessary\n\tif err := os.MkdirAll(directoryPath, os.FileMode(DefaultFileMode)); err != nil {\n\t\treturn nil, err\n\t}\n\n\topts := badger.DefaultOptions(directoryPath)\n\tbadgerLogger := context.DefaultLogger(\"sessionsdb.badger\").DisableNewLine()\n\topts.Logger = badgerLogger\n\n\tservice, err := badger.Open(opts)\n\tif err != nil {\n\t\tbadgerLogger.Errorf(\"unable to initialize the badger-based session database: %v\\n\", err)","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/sessions/sessiondb/badger/database.go#L27-L63","documentation":"The Badger session database's New constructor validates that the directoryPath argument is non-empty and returns this error before opening the store. Badger needs a filesystem directory in which to store its LSM/SST files, so an empty path is rejected immediately.","triggerScenarios":"Calling badger.New(\"\") when wiring sessions: e.g. sessions.New(sessions.Config{...}, badger.New(\"\")) or db, err := badger.New(\"\") — commonly when the path comes from an unset environment variable or empty config field.","commonSituations":"Env var like SESSION_DB_DIR not set in a container/deployment; YAML/JSON config with a missing directoryPath key; copying sample code and forgetting to fill the path.","solutions":["Pass a valid directory path, e.g. badger.New(\"./sessions/\").","Load the path from configuration and fail fast at startup if empty.","Create the directory beforehand or rely on the constructor (badger creates it) but always supply it."],"exampleFix":"// before\ndb, err := badger.New(\"\") // error: directoryPath is empty\n\n// after\ndb, err := badger.New(\"./sessions/\")","handlingStrategy":"validation","validationCode":"if os.Getenv(\"SESSION_BADGER_DIR\") == \"\" {\n    log.Fatal(\"SESSION_BADGER_DIR env var is required\")\n}\ndb, err := badger.New(os.Getenv(\"SESSION_BADGER_DIR\"))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fail fast at boot when configured paths are empty.","Provide sane defaults like ./sessions/.","Never construct session DBs inline with unvalidated config strings."],"tags":["sessions","badger","configuration","iris"],"backgroundTag":"missing-config-path","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}