From 4b4b75010e8ffa44927106466fb9469803c3feac Mon Sep 17 00:00:00 2001 From: "blink-so[bot]" <211532188+blink-so[bot]@users.noreply.github.com> Date: Mon, 21 Jul 2025 21:32:51 +0000 Subject: [PATCH] Improve error message for rich-parameters API when no provisioners are running When the rich-parameters API endpoint is called and the job hasn't completed, the previous error message 'Job hasn't completed!' was unhelpful and didn't explain why the job was stuck. This change enhances the error handling to: 1. Check if there are any active provisioners for the organization 2. If no active provisioners are found, return a clear error message explaining that provisioners are needed and providing actionable guidance 3. If provisioners are available but the job still hasn't completed, fall back to the original error message The new error message helps users understand that they need to start a provisioner or contact their administrator to resolve template parameter resolution issues. Fixes: https://github.com/coder/coder/issues/18979 Co-authored-by: angrycub <464492+angrycub@users.noreply.github.com> --- coderd/provisionerjobs.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/coderd/provisionerjobs.go b/coderd/provisionerjobs.go index 800b2916efef3..940d55ba3433a 100644 --- a/coderd/provisionerjobs.go +++ b/coderd/provisionerjobs.go @@ -9,6 +9,7 @@ import ( "net/http" "sort" "strconv" + "time" "github.com/google/uuid" "golang.org/x/xerrors" @@ -17,10 +18,12 @@ import ( "github.com/coder/coder/v2/coderd/database" "github.com/coder/coder/v2/coderd/database/db2sdk" "github.com/coder/coder/v2/coderd/database/dbauthz" + "github.com/coder/coder/v2/coderd/database/dbtime" "github.com/coder/coder/v2/coderd/database/pubsub" "github.com/coder/coder/v2/coderd/httpapi" "github.com/coder/coder/v2/coderd/httpmw" "github.com/coder/coder/v2/coderd/httpmw/loggermw" + "github.com/coder/coder/v2/coderd/provisionerdserver" "github.com/coder/coder/v2/coderd/rbac" "github.com/coder/coder/v2/coderd/rbac/policy" "github.com/coder/coder/v2/coderd/util/slice" @@ -188,6 +191,32 @@ func (api *API) provisionerJobLogs(rw http.ResponseWriter, r *http.Request, job func (api *API) provisionerJobResources(rw http.ResponseWriter, r *http.Request, job database.ProvisionerJob) { ctx := r.Context() if !job.CompletedAt.Valid { + // Check if there are any active provisioners for this organization + daemons, err := api.Database.GetProvisionerDaemonsByOrganization(ctx, database.GetProvisionerDaemonsByOrganizationParams{ + OrganizationID: job.OrganizationID, + WantTags: database.StringMap{}, + }) + if err != nil { + // If we can't check provisioners, fall back to the original error + httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ + Message: "Job hasn't completed!", + }) + return + } + + // Check if any provisioners are active (not stale) + now := dbtime.Now() + activeProvisioners := db2sdk.RecentProvisionerDaemons(now, provisionerdserver.StaleInterval, daemons) + + if len(activeProvisioners) == 0 { + httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ + Message: "No provisioners are currently running for this organization. Please start a provisioner or contact your administrator to enable template parameter resolution.", + Detail: "Template parameter resolution requires an active provisioner to process the job.", + }) + return + } + + // Provisioners are available but job still hasn't completed httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ Message: "Job hasn't completed!", })
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: