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

  1. Check the datasource config and set DataSource.Port to a bare numeric string such as "1521"
  2. Trim whitespace from the port value before constructing ConnectionConfig
  3. 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

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


AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06). Data as JSON: /api/errors/189ba5efb50ed0d5. Report an issue: GitHub.