Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
CR's fixes
  • Loading branch information
evgeniy-scherbina committed Apr 28, 2025
commit ffac93361f891fc38ef0cce8ee645d4ecbd5b8aa
25 changes: 19 additions & 6 deletions coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,13 +652,26 @@ func createWorkspace(
claimedWorkspace, err = claimPrebuild(ctx, prebuildsClaimer, db, api.Logger, req, owner)
// If claiming fails with an expected error (no claimable prebuilds or AGPL does not support prebuilds),
// we fall back to creating a new workspace. Otherwise, propagate the unexpected error.
if err != nil &&
!errors.Is(err, prebuilds.ErrNoClaimablePrebuiltWorkspaces) &&
!errors.Is(err, prebuilds.ErrAGPLDoesNotSupportPrebuiltWorkspaces) {
api.Logger.Error(ctx, "failed to claim prebuilt workspace", slog.Error(err),
slog.F("workspace_name", req.Name), slog.F("template_version_preset_id", req.TemplateVersionPresetID))
if err != nil {
isExpectedError := errors.Is(err, prebuilds.ErrNoClaimablePrebuiltWorkspaces) ||
errors.Is(err, prebuilds.ErrAGPLDoesNotSupportPrebuiltWorkspaces)
fields := []any{
slog.Error(err),
slog.F("workspace_name", req.Name),
slog.F("template_version_preset_id", req.TemplateVersionPresetID),
}

if !isExpectedError {
// if it's an unexpected error - use error log level
api.Logger.Error(ctx, "failed to claim prebuilt workspace", fields...)

return xerrors.Errorf("failed to claim prebuilt workspace: %w", err)
}

// if it's an expected error - use warn log level
api.Logger.Warn(ctx, "failed to claim prebuilt workspace", fields...)

return xerrors.Errorf("failed to claim prebuilt workspace: %w", err)
// fall back to creating a new workspace
}
}

Expand Down