Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffac933

Browse files
CR's fixes
1 parent a4954e4 commit ffac933

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

coderd/workspaces.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -652,13 +652,26 @@ func createWorkspace(
652652
claimedWorkspace, err = claimPrebuild(ctx, prebuildsClaimer, db, api.Logger, req, owner)
653653
// If claiming fails with an expected error (no claimable prebuilds or AGPL does not support prebuilds),
654654
// we fall back to creating a new workspace. Otherwise, propagate the unexpected error.
655-
if err != nil &&
656-
!errors.Is(err, prebuilds.ErrNoClaimablePrebuiltWorkspaces) &&
657-
!errors.Is(err, prebuilds.ErrAGPLDoesNotSupportPrebuiltWorkspaces) {
658-
api.Logger.Error(ctx, "failed to claim prebuilt workspace", slog.Error(err),
659-
slog.F("workspace_name", req.Name), slog.F("template_version_preset_id", req.TemplateVersionPresetID))
655+
if err != nil {
656+
isExpectedError := errors.Is(err, prebuilds.ErrNoClaimablePrebuiltWorkspaces) ||
657+
errors.Is(err, prebuilds.ErrAGPLDoesNotSupportPrebuiltWorkspaces)
658+
fields := []any{
659+
slog.Error(err),
660+
slog.F("workspace_name", req.Name),
661+
slog.F("template_version_preset_id", req.TemplateVersionPresetID),
662+
}
663+
664+
if !isExpectedError {
665+
// if it's an unexpected error - use error log level
666+
api.Logger.Error(ctx, "failed to claim prebuilt workspace", fields...)
667+
668+
return xerrors.Errorf("failed to claim prebuilt workspace: %w", err)
669+
}
670+
671+
// if it's an expected error - use warn log level
672+
api.Logger.Warn(ctx, "failed to claim prebuilt workspace", fields...)
660673

661-
return xerrors.Errorf("failed to claim prebuilt workspace: %w", err)
674+
// fall back to creating a new workspace
662675
}
663676
}
664677

0 commit comments

Comments
 (0)