golang-migrate/migrate · error
invalid host
Error message
invalid host
What it means
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.
Source
Thrown at source/gitlab/gitlab.go:26
nurl "net/url"
"os"
"strconv"
"strings"
"github.com/golang-migrate/migrate/v4/source"
"github.com/xanzy/go-gitlab"
)
func init() {
source.Register("gitlab", &Gitlab{})
}
const DefaultMaxItemsPerPage = 100
var (
ErrNoUserInfo = fmt.Errorf("no username:token provided")
ErrNoAccessToken = fmt.Errorf("no access token")
ErrInvalidHost = fmt.Errorf("invalid host")
ErrInvalidProjectID = fmt.Errorf("invalid project id")
ErrInvalidResponse = fmt.Errorf("invalid response")
)
type Gitlab struct {
client *gitlab.Client
url string
projectID string
path string
listOptions *gitlab.ListTreeOptions
getOptions *gitlab.GetFileOptions
migrations *source.Migrations
}
type Config struct {
}
View on GitHub (pinned to 01a9643f14)
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://
Example fix
// before
db.Open("gitlab:///mygroup/myproject") // no host -> invalid host
// after
db.Open("gitlab://oauth2:glpat-xxxx@gitlab.mycompany.com/mygroup/myproject") Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(host)
if err != nil || u.Host == "" {
return fmt.Errorf("bad gitlab host: %w", err)
}
if u.Scheme != "http" && u.Scheme != "https" {
return fmt.Errorf("unsupported scheme %q", u.Scheme)
} Try / catch
d, err := gitlabDriver.Open(gitlabURL)
if errors.Is(err, gitlab.ErrInvalidHost) {
log.Fatalf("check the host in %s: %v", gitlabURL, err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02).
Data as JSON: /api/errors/a5ed0247ea628d2a.
Report an issue: GitHub.