{"record":{"id":"681750e1a0583a6b","repo":"benbjohnson/litestream","slug":"failed-to-expand-meta-path-w","errorCode":null,"errorMessage":"failed to expand meta path: %w","messagePattern":"failed to expand meta path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/main.go","lineNumber":762,"sourceCode":"// NewDBFromConfig instantiates a DB based on a configuration.\nfunc NewDBFromConfig(dbc *DBConfig) (*litestream.DB, error) {\n\tif dbc.MetaDir != nil {\n\t\treturn nil, fmt.Errorf(\"'meta-dir' can only be used with a directory\")\n\t}\n\n\tconfigPath, err := expand(dbc.Path)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Initialize database with given path.\n\tdb := litestream.NewDB(configPath)\n\n\t// Override default database settings if specified in configuration.\n\tif dbc.MetaPath != nil {\n\t\texpandedMetaPath, err := expand(*dbc.MetaPath)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to expand meta path: %w\", err)\n\t\t}\n\t\tdbc.MetaPath = &expandedMetaPath\n\t\tdb.SetMetaPath(expandedMetaPath)\n\t}\n\tif dbc.MonitorInterval != nil {\n\t\tdb.MonitorInterval = *dbc.MonitorInterval\n\t}\n\tif dbc.CheckpointInterval != nil {\n\t\tdb.CheckpointInterval = *dbc.CheckpointInterval\n\t}\n\tif dbc.BusyTimeout != nil {\n\t\tdb.BusyTimeout = *dbc.BusyTimeout\n\t}\n\tif dbc.MinCheckpointPageN != nil {\n\t\tdb.MinCheckpointPageN = *dbc.MinCheckpointPageN\n\t}\n\tif dbc.TruncatePageN != nil {\n\t\tdb.TruncatePageN = *dbc.TruncatePageN","sourceCodeStart":744,"sourceCodeEnd":780,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/main.go#L744-L780","documentation":"NewDBFromConfig expands environment variables in dbc.MetaPath via expand(); if expansion fails (e.g. a referenced env variable is unset in strict setups), it wraps the error with \"failed to expand meta path: %w\" and aborts DB creation.","triggerScenarios":"A database entry with `meta-path:` containing variables (e.g. ${HOME} or $PID-style placeholders) whose expansion function returns an error, hit when Run/newDBFromDirectoryEntry/loadFromConfig calls NewDBFromConfig.","commonSituations":"Config uses $VAR syntax relying on environment variables that are not set in the service environment (systemd unit without Environment=); quoting issues in YAML around $.","solutions":["Ensure every env variable referenced in meta-path is defined in the runtime environment.","Simplify meta-path to a literal path to avoid expansion entirely.","Check the wrapped inner error (%w) for the exact expansion failure and fix accordingly."],"exampleFix":"# before\nmeta-path: ${LITESTREAM_META_DIR}/app\n# after (env guaranteed via systemd)\n# systemd unit:\nEnvironment=LITESTREAM_META_DIR=/var/lib/litestream-meta\n# config\nmeta-path: ${LITESTREAM_META_DIR}/app","handlingStrategy":"validation","validationCode":"for _, v := range envRefs(metaPath) {\n    if os.Getenv(v) == \"\" {\n        return fmt.Errorf(\"env var %s used in meta-path is unset\", v)\n    }\n}","typeGuard":null,"tryCatchPattern":"db, err := litestream.NewDBFromConfig(dbc)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to expand meta path\") {\n        log.Fatalf(\"check env vars in meta-path: %v\", err)\n    }\n}","preventionTips":["Define all referenced env vars in systemd/launcher environments","Prefer literal paths over $VAR in meta-path","Test expansion with the exact service environment"],"tags":["config","env","litestream"],"backgroundTag":"invalid-env-var-value","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}