bytebase/bytebase · error
invalid port %q
Error message
invalid port %q
What it means
The Oracle driver's Open() parses config.DataSource.Port with strconv.Atoi; if the port string is not a valid integer it aborts connection setup with this error. It fires before any network attempt, so the datasource configuration itself is bad.
Source
Thrown at backend/plugin/db/oracle/oracle.go:59
databaseName string
serviceName string
connectionCtx db.ConnectionContext
}
func newDriver() db.Driver {
return &Driver{}
}
// GetVersion gets the Oracle version.
func (d *Driver) GetVersion() (*plsqlparser.Version, error) {
return plsqlparser.ParseVersion(d.connectionCtx.EngineVersion)
}
// Open opens a Oracle driver.
func (d *Driver) Open(ctx context.Context, _ storepb.Engine, config db.ConnectionConfig) (db.Driver, error) {
port, err := strconv.Atoi(config.DataSource.Port)
if err != nil {
return nil, errors.Errorf("invalid port %q", config.DataSource.Port)
}
options := make(map[string]string)
options["CONNECTION TIMEOUT"] = "0"
if config.DataSource.GetSid() != "" {
options["SID"] = config.DataSource.GetSid()
}
for key, value := range config.DataSource.GetExtraConnectionParameters() {
options[key] = value
}
dsn := goora.BuildUrl(config.DataSource.Host, port, config.DataSource.GetServiceName(), config.DataSource.Username, config.Password, options)
db, err := sql.Open("oracle", dsn)
if err != nil {
return nil, err
}
if config.ConnectionContext.DatabaseName != "" {
if _, err := db.ExecContext(ctx, fmt.Sprintf("ALTER SESSION SET CURRENT_SCHEMA = \"%s\"", config.ConnectionContext.DatabaseName)); err != nil {
return nil, errors.Wrapf(err, "failed to set current schema to %q", config.ConnectionContext.DatabaseName)
}View on GitHub (pinned to 1870550677)
Solutions
- Check the datasource config and set DataSource.Port to a bare numeric string such as "1521"
- Trim whitespace from the port value before constructing ConnectionConfig
- If port comes from user input, validate with strconv.Atoi on the client side before saving the instance
Example fix
// before Port: "localhost:1521" // after Port: "1521"
Defensive patterns
Strategy: validation
Validate before calling
if p := strings.TrimSpace(cfg.DataSource.Port); p == "" { return errors.New("port is required") }
if _, err := strconv.Atoi(p); err != nil { return fmt.Errorf("invalid port %q", p) }
cfg.DataSource.Port = p Try / catch
if _, err := d.Open(ctx, engine, cfg); err != nil {
var numErr *strconv.NumError
if errors.As(err, nil) || strings.Contains(err.Error(), "invalid port") {
// fix datasource config before retrying
}
} Prevention
- Always store the port as a bare numeric string
- Trim and validate user-supplied port fields at form/UI level
- Add a config schema check (regex ^\d{1,5}$) before constructing ConnectionConfig
When it happens
Trigger: Calling driver.Open with a ConnectionConfig whose DataSource.Port is empty, contains non-numeric characters, whitespace, or a 'host:port' pair instead of a bare port number.
Common situations: Datasource YAML/JSON with a missing or blank port field; users pasting 'localhost:1521' into the port field; leading/trailing spaces from form input.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- issuer_url is required for OIDC
- number_payload is required for this rule
- number_payload is required for this rule
- string_array_payload is required for column required rule
- number_payload is required for this rule
AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06).
Data as JSON: /api/errors/189ba5efb50ed0d5.
Report an issue: GitHub.