{"record":{"id":"189ba5efb50ed0d5","repo":"bytebase/bytebase","slug":"invalid-port-q","errorCode":null,"errorMessage":"invalid port %q","messagePattern":"invalid port %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/plugin/db/oracle/oracle.go","lineNumber":59,"sourceCode":"\tdatabaseName  string\n\tserviceName   string\n\tconnectionCtx db.ConnectionContext\n}\n\nfunc newDriver() db.Driver {\n\treturn &Driver{}\n}\n\n// GetVersion gets the Oracle version.\nfunc (d *Driver) GetVersion() (*plsqlparser.Version, error) {\n\treturn plsqlparser.ParseVersion(d.connectionCtx.EngineVersion)\n}\n\n// Open opens a Oracle driver.\nfunc (d *Driver) Open(ctx context.Context, _ storepb.Engine, config db.ConnectionConfig) (db.Driver, error) {\n\tport, err := strconv.Atoi(config.DataSource.Port)\n\tif err != nil {\n\t\treturn nil, errors.Errorf(\"invalid port %q\", config.DataSource.Port)\n\t}\n\toptions := make(map[string]string)\n\toptions[\"CONNECTION TIMEOUT\"] = \"0\"\n\tif config.DataSource.GetSid() != \"\" {\n\t\toptions[\"SID\"] = config.DataSource.GetSid()\n\t}\n\tfor key, value := range config.DataSource.GetExtraConnectionParameters() {\n\t\toptions[key] = value\n\t}\n\tdsn := goora.BuildUrl(config.DataSource.Host, port, config.DataSource.GetServiceName(), config.DataSource.Username, config.Password, options)\n\tdb, err := sql.Open(\"oracle\", dsn)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif config.ConnectionContext.DatabaseName != \"\" {\n\t\tif _, err := db.ExecContext(ctx, fmt.Sprintf(\"ALTER SESSION SET CURRENT_SCHEMA = \\\"%s\\\"\", config.ConnectionContext.DatabaseName)); err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"failed to set current schema to %q\", config.ConnectionContext.DatabaseName)\n\t\t}","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/plugin/db/oracle/oracle.go#L41-L77","documentation":"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.","triggerScenarios":"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.","commonSituations":"Datasource YAML/JSON with a missing or blank port field; users pasting 'localhost:1521' into the port field; leading/trailing spaces from form input.","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"],"exampleFix":"// before\nPort: \"localhost:1521\"\n// after\nPort: \"1521\"","handlingStrategy":"validation","validationCode":"if p := strings.TrimSpace(cfg.DataSource.Port); p == \"\" { return errors.New(\"port is required\") }\nif _, err := strconv.Atoi(p); err != nil { return fmt.Errorf(\"invalid port %q\", p) }\ncfg.DataSource.Port = p","typeGuard":null,"tryCatchPattern":"if _, err := d.Open(ctx, engine, cfg); err != nil {\n    var numErr *strconv.NumError\n    if errors.As(err, nil) || strings.Contains(err.Error(), \"invalid port\") {\n        // fix datasource config before retrying\n    }\n}","preventionTips":["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"],"tags":["oracle","config","port","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}