{"record":{"id":"a5ed0247ea628d2a","repo":"golang-migrate/migrate","slug":"invalid-host","errorCode":null,"errorMessage":"invalid host","messagePattern":"invalid host","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"source/gitlab/gitlab.go","lineNumber":26,"sourceCode":"\tnurl \"net/url\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/golang-migrate/migrate/v4/source\"\n\t\"github.com/xanzy/go-gitlab\"\n)\n\nfunc init() {\n\tsource.Register(\"gitlab\", &Gitlab{})\n}\n\nconst DefaultMaxItemsPerPage = 100\n\nvar (\n\tErrNoUserInfo       = fmt.Errorf(\"no username:token provided\")\n\tErrNoAccessToken    = fmt.Errorf(\"no access token\")\n\tErrInvalidHost      = fmt.Errorf(\"invalid host\")\n\tErrInvalidProjectID = fmt.Errorf(\"invalid project id\")\n\tErrInvalidResponse  = fmt.Errorf(\"invalid response\")\n)\n\ntype Gitlab struct {\n\tclient *gitlab.Client\n\turl    string\n\n\tprojectID   string\n\tpath        string\n\tlistOptions *gitlab.ListTreeOptions\n\tgetOptions  *gitlab.GetFileOptions\n\tmigrations  *source.Migrations\n}\n\ntype Config struct {\n}\n","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/source/gitlab/gitlab.go#L8-L44","documentation":"ErrInvalidHost is a sentinel error returned by gitlab.Open when the gitlab client cannot be constructed for the given host URL. Open parses the URL from the connection string and calls client.SetBaseURL; if the resulting URL is rejected by the gitlab client (malformed scheme, empty host, invalid characters), this error is returned to signal the configured host is unusable.","triggerScenarios":"Calling Open (or database.Open with a gitlab:// URL) where the URL fails to parse or SetBaseURL rejects it: missing host, unsupported scheme, malformed URL components, or the URL context being required but absent.","commonSituations":"Typo'd gitlab:// connection string (e.g. gitlab:///repo with no host when one is required), unescaped special characters in the URL, or pointing at a non-GitLab endpoint whose URL is rejected client-side before any network request.","solutions":["Verify the gitlab:// URL in your connection string has a valid host, e.g. gitlab://user:token@gitlab.example.com/group/project","Ensure the URL parses (use net/url.Parse on the host portion yourself to pre-validate) and includes the scheme","Escape special characters (spaces, @, :) in the host/token via url.PathEscape or percent-encoding","If running a self-hosted GitLab, confirm the base URL is reachable and uses http:// or https://"],"exampleFix":"// before\ndb.Open(\"gitlab:///mygroup/myproject\") // no host -> invalid host\n// after\ndb.Open(\"gitlab://oauth2:glpat-xxxx@gitlab.mycompany.com/mygroup/myproject\")","handlingStrategy":"validation","validationCode":"u, err := url.Parse(host)\nif err != nil || u.Host == \"\" {\n    return fmt.Errorf(\"bad gitlab host: %w\", err)\n}\nif u.Scheme != \"http\" && u.Scheme != \"https\" {\n    return fmt.Errorf(\"unsupported scheme %q\", u.Scheme)\n}","typeGuard":null,"tryCatchPattern":"d, err := gitlabDriver.Open(gitlabURL)\nif errors.Is(err, gitlab.ErrInvalidHost) {\n    log.Fatalf(\"check the host in %s: %v\", gitlabURL, err)\n}","preventionTips":["Store the full gitlab:// URL in config/env and validate it at startup","Percent-encode credentials embedded in the URL","Pin to https:// for self-hosted GitLab and test with curl first"],"tags":["gitlab","url","config","connection"],"backgroundTag":"invalid-base-url","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}