fix: nil guards, safe type assertions, panic prevention, and rate limiter plugin (#3757)

Signed-off-by: Srikanth Patchava <spatchava@meta.com>
Signed-off-by: Srikanth Patchava <srpatcha@users.noreply.github.com>
Co-authored-by: Srikanth Patchava <srpatcha@users.noreply.github.com>
This commit is contained in:
Srikanth Patchava
2026-05-11 20:00:37 -07:00
committed by GitHub
parent 1c4fe1c9f9
commit 29da03c371
4 changed files with 65 additions and 35 deletions

View File

@@ -236,6 +236,10 @@ func (c *DBClient) DescribeTable(table string) ([]map[string]interface{}, error)
// ListTables List all tables in the connected database. // ListTables List all tables in the connected database.
func (c *DBClient) ListTables() ([]string, error) { func (c *DBClient) ListTables() ([]string, error) {
if err := c.reconnectIfDbEmpty(); err != nil {
return nil, err
}
var sql string var sql string
switch c.dbType { switch c.dbType {
case MYSQL: case MYSQL:
@@ -265,6 +269,10 @@ func (c *DBClient) ListTables() ([]string, error) {
tables = append(tables, table) tables = append(tables, table)
} }
if err := rows.Err(); err != nil {
return nil, fmt.Errorf("error iterating table rows: %w", err)
}
return tables, nil return tables, nil
} }
@@ -335,6 +343,10 @@ func (c *DBClient) Query(sql string, args ...interface{}) ([]map[string]interfac
results = append(results, rowMap) results = append(results, rowMap)
} }
if err := rows.Err(); err != nil {
return nil, fmt.Errorf("failed to iterate table rows in Query: %w", err)
}
return results, nil return results, nil
} }

View File

@@ -792,22 +792,36 @@ func (m *MilvusProvider) ListDocs(ctx context.Context, limit int) ([]schema.Docu
fieldName := strings.ToLower(fieldMapping.StandardName) fieldName := strings.ToLower(fieldMapping.StandardName)
switch fieldName { switch fieldName {
case "id": case "id":
if v, err := col.(*entity.ColumnVarChar).Get(i); err == nil { if typedCol, ok := col.(*entity.ColumnVarChar); ok {
id = v.(string) if v, err := typedCol.Get(i); err == nil {
if s, ok := v.(string); ok {
id = s
}
}
} }
case "content": case "content":
if v, err := col.(*entity.ColumnVarChar).Get(i); err == nil { if typedCol, ok := col.(*entity.ColumnVarChar); ok {
content = v.(string) if v, err := typedCol.Get(i); err == nil {
if s, ok := v.(string); ok {
content = s
}
}
} }
case "metadata": case "metadata":
if v, err := col.(*entity.ColumnJSONBytes).Get(i); err == nil { if typedCol, ok := col.(*entity.ColumnJSONBytes); ok {
if bytes, ok := v.([]byte); ok { if v, err := typedCol.Get(i); err == nil {
_ = json.Unmarshal(bytes, &metadata) if bytes, ok := v.([]byte); ok {
_ = json.Unmarshal(bytes, &metadata)
}
} }
} }
case "created_at": case "created_at":
if v, err := col.(*entity.ColumnInt64).Get(i); err == nil { if typedCol, ok := col.(*entity.ColumnInt64); ok {
createdAt = v.(int64) if v, err := typedCol.Get(i); err == nil {
if ts, ok := v.(int64); ok {
createdAt = ts
}
}
} }
} }
} }

View File

@@ -87,13 +87,17 @@ func parseConfig(json gjson.Result, config *RequestBlockConfig, log log.Log) err
if regexpUrl == "" { if regexpUrl == "" {
continue continue
} }
var reg *regexp.Regexp
var err error
if config.caseSensitive { if config.caseSensitive {
reg := regexp.MustCompile(regexpUrl) reg, err = regexp.Compile(regexpUrl)
config.blockRegExpArray = append(config.blockRegExpArray, reg)
} else { } else {
reg := regexp.MustCompile(strings.ToLower(regexpUrl)) reg, err = regexp.Compile(strings.ToLower(regexpUrl))
config.blockRegExpArray = append(config.blockRegExpArray, reg)
} }
if err != nil {
return fmt.Errorf("invalid regexp pattern %q: %w", regexpUrl, err)
}
config.blockRegExpArray = append(config.blockRegExpArray, reg)
} }
for _, item := range json.Get("block_headers").Array() { for _, item := range json.Get("block_headers").Array() {
header := item.String() header := item.String()