Skip to content

Commit

Permalink
fix: check for NotFoundInWorkspaceError to avoid transient errors (#600)
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams authored Nov 15, 2024
1 parent c7e39e2 commit 2df7a4a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pkg/controller/handlers/knowledgesource/knowledgesource.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ func safeStatusSave(ctx context.Context, c kclient.Client, source *v1.KnowledgeS
}
func (k *Handler) saveProgress(ctx context.Context, c kclient.Client, source *v1.KnowledgeSource, thread *v1.Thread, complete bool) error {
files, syncMetadata, err := k.getMetadata(ctx, source, thread)
if err != nil {
if err != nil || syncMetadata == nil {
return err
}

apply := apply.New(c)
if !complete {
apply = apply.WithNoPrune()
}
if err := apply.Apply(ctx, source, files...); err != nil {
if err = apply.Apply(ctx, source, files...); err != nil {
return err
}

Expand Down Expand Up @@ -226,7 +227,7 @@ func (k *Handler) Sync(req router.Request, _ router.Response) error {
source.Status.SyncState = types.KnowledgeSourceStateSyncing
source.Status.ThreadName = task.Thread.Name
source.Status.RunName = task.Run.Name
if err := req.Client.Status().Update(req.Ctx, source); err != nil {
if err = req.Client.Status().Update(req.Ctx, source); err != nil {
return err
}

Expand All @@ -242,7 +243,7 @@ forLoop:
break forLoop
}
case <-ticker.C:
if err := k.saveProgress(req.Ctx, req.Client, source, thread, false); err != nil {
if err = k.saveProgress(req.Ctx, req.Client, source, thread, false); err != nil {
// Ignore these errors, hopefully transient
log.Errorf("failed to get files for knowledgesource [%s]: %v", source.Name, err)
}
Expand All @@ -251,7 +252,7 @@ forLoop:

_, taskErr := task.Result(req.Ctx)

if err := k.saveProgress(req.Ctx, req.Client, source, thread, taskErr == nil); err != nil {
if err = k.saveProgress(req.Ctx, req.Client, source, thread, taskErr == nil); err != nil {
log.Errorf("failed to save files for knowledgesource [%s]: %v", source.Name, err)
if taskErr == nil {
taskErr = err
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/handlers/knowledgesource/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (k *Handler) getMetadata(ctx context.Context, source *v1.KnowledgeSource, t
data, err := k.gptClient.ReadFileInWorkspace(ctx, ".metadata.json", gptscript.ReadFileInWorkspaceOptions{
WorkspaceID: thread.Status.WorkspaceID,
})
if errNotFound := new(gptscript.ErrNotFound); errors.As(err, &errNotFound) {
if errNotFound := new(gptscript.NotFoundInWorkspaceError); errors.As(err, &errNotFound) {
return nil, nil, nil
} else if err != nil {
return nil, nil, fmt.Errorf("failed to read metadata.json: %w", err)
Expand Down

0 comments on commit 2df7a4a

Please sign in to comment.