{"record":{"id":"b5a19aac9703be8b","repo":"golang-migrate/migrate","slug":"url-cannot-be-empty","errorCode":null,"errorMessage":"URL cannot be empty","messagePattern":"URL cannot be empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/url/url.go","lineNumber":9,"sourceCode":"package url\n\nimport (\n\t\"errors\"\n\t\"strings\"\n)\n\nvar errNoScheme = errors.New(\"no scheme\")\nvar errEmptyURL = errors.New(\"URL cannot be empty\")\n\n// schemeFromURL returns the scheme from a URL string\nfunc SchemeFromURL(url string) (string, error) {\n\tif url == \"\" {\n\t\treturn \"\", errEmptyURL\n\t}\n\n\ti := strings.Index(url, \":\")\n\n\t// No : or : is the first character.\n\tif i < 1 {\n\t\treturn \"\", errNoScheme\n\t}\n\n\treturn url[0:i], nil\n}\n","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/internal/url/url.go#L1-L26","documentation":"SchemeFromURL (internal/url/url.go) parses a scheme out of a migration URL string. If the URL is the empty string, there is nothing to parse, so it returns errEmptyURL (\"URL cannot be empty\") immediately instead of attempting scheme extraction. This guards the driver-lookup path in database/source Open functions which need a scheme to select a driver.","triggerScenarios":"Calling SchemeFromURL(\"\") directly, or calling a database/source driver Open (e.g. database.Open, source.Open) with an empty URL string (e.g. migrate.New(\"\", path), or a DSN sourced from an unset environment variable).","commonSituations":"DATABASE_URL or similar env var is empty/unset; config struct field left at zero value; template rendering produced an empty connection string; passing \"\" for the URL argument of migrate.New/migrate.NewWithDatabaseInstance plumbing.","solutions":["Set the URL before calling: pass a non-empty connection string like \"postgres://user:pass@host:5432/db\" to migrate.New or the driver's Open.","Validate the env var / config field is non-empty before invoking the library (os.Getenv check).","If reading from config files, check for empty string after loading and fail early with your own clearer message."],"exampleFix":"// before\nm, err := migrate.New(os.Getenv(\"MIGRATION_URL\"), \"file://migrations\")\n// after\nurl := os.Getenv(\"MIGRATION_URL\")\nif url == \"\" {\n    log.Fatal(\"MIGRATION_URL environment variable is not set\")\n}\nm, err := migrate.New(url, \"file://migrations\")","handlingStrategy":"validation","validationCode":"if u == \"\" {\n    return fmt.Errorf(\"migration URL is required\")\n}\n_, err := iurl.SchemeFromURL(u) // or just ensure non-empty before migrate.New","typeGuard":null,"tryCatchPattern":"if _, err := migrate.New(url, sourcePath); err != nil {\n    if err.Error() == \"URL cannot be empty\" { /* handle empty config */ }\n}","preventionTips":["Check os.Getenv(\"DATABASE_URL\") != \"\" at startup and fail fast with a clear message.","Validate all connection strings during config loading, before any library calls.","Default empty URLs to a documented local development DSN in dev environments."],"tags":["url","configuration","validation"],"backgroundTag":"empty-url","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}