fix(container): propagate host project lookup errors (#3611)

main
dvd233 2026-09-25 18:51:54 +08:00 committed by GitHub
parent d9444683da
commit 0cb1e57fae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -4,6 +4,7 @@ package container
import (
"context"
"errors"
"strings"
"gorm.io/gorm"
@ -37,7 +38,10 @@ func (l *hostProjectLookupImpl) ProjectDirForSession(ctx context.Context, sessio
Where("id = ?", sessionID).
First(&sess).Error
if err != nil {
return "", false, nil
if errors.Is(err, gorm.ErrRecordNotFound) {
return "", false, nil
}
return "", false, err
}
raw := strings.TrimSpace(sess.HostWorkspaceDir)
if raw == "" {

View File

@ -83,3 +83,19 @@ func TestProjectLookupReturnsFalseForUnknownSession(t *testing.T) {
require.False(t, ok)
require.Empty(t, dir)
}
func TestProjectLookupPropagatesDatabaseErrors(t *testing.T) {
db := hostProjectLookupTestDB(t)
projectDir := t.TempDir()
insertHostSession(t, db, "sess-1", projectDir)
ctx, cancel := context.WithCancel(context.Background())
cancel()
lookup := newHostProjectLookup(db, func() []string {
return []string{projectDir}
})
dir, ok, err := lookup.ProjectDirForSession(ctx, "sess-1")
require.ErrorIs(t, err, context.Canceled)
require.False(t, ok)
require.Empty(t, dir)
}