mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-12 11:34:30 -05:00
Fix nil pointer panic in workspace table Update and Delete methods (#10590)
When StatementBegin encounters an error (e.g., table not found in staging root), it stores the error in wtu.err but leaves tableWriter as nil. The Update and Delete methods were dereferencing tableWriter before checking if it was nil, causing a panic. This fix adds an early return to check for errors from StatementBegin before attempting to use tableWriter, preventing the nil pointer dereference.
This commit is contained in:
@@ -147,6 +147,10 @@ func (wtm *WorkspaceTableModifier) statementComplete(ctx *sql.Context) error {
|
||||
}
|
||||
|
||||
func (wtu *WorkspaceTableUpdater) Update(ctx *sql.Context, old sql.Row, new sql.Row) error {
|
||||
if wtu.err != nil {
|
||||
return *wtu.err
|
||||
}
|
||||
|
||||
if old == nil || new == nil {
|
||||
return fmt.Errorf("Runtime error: expected non-nil inputs to WorkspaceTableUpdater.Update")
|
||||
}
|
||||
@@ -209,6 +213,10 @@ func (wtd *WorkspaceTableDeleter) StatementBegin(ctx *sql.Context) {
|
||||
}
|
||||
|
||||
func (wtd *WorkspaceTableDeleter) Delete(c *sql.Context, row sql.Row) error {
|
||||
if wtd.err != nil {
|
||||
return *wtd.err
|
||||
}
|
||||
|
||||
if !wtd.modifiable {
|
||||
return errors.New(fmt.Sprintf("%s table is not modifiable due to schema change", wtd.workspaceTableName))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user