{"record":{"id":"d47658bc3adc6d74","repo":"slimtoolkit/slim","slug":"building-environment-v","errorCode":null,"errorMessage":"building environment: %v","messagePattern":"building environment: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/probe/http/internal/fastcgi.go","lineNumber":76,"sourceCode":"\n\t// The duration used to set a deadline when sending to the FastCGI server.\n\tWriteTimeout time.Duration\n}\n\n// init sets up t.\nfunc (t *FastCGITransport) init() {\n\tif t.Root == \"\" {\n\t\tt.Root = \"/\"\n\t}\n}\n\n// RoundTrip implements http.RoundTripper.\nfunc (t FastCGITransport) RoundTrip(r *http.Request) (*http.Response, error) {\n\tt.init()\n\n\tenv, err := t.buildEnv(r)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"building environment: %v\", err)\n\t}\n\n\tnetwork, address := \"tcp\", r.URL.Host\n\n\tif log.IsLevelEnabled(log.DebugLevel) {\n\t\tenvJSON, _ := json.Marshal(env)\n\t\tlog.Debugf(\"HTTP probe - FastCGI env - %s\", string(envJSON))\n\t}\n\n\tctx := r.Context()\n\tdialer := net.Dialer{Timeout: t.DialTimeout}\n\tfcgiBackend, err := DialWithDialerContext(ctx, network, address, dialer)\n\tif err != nil {\n\t\t// TODO: wrap in a special error type if the dial failed, so retries can happen if enabled\n\t\treturn nil, fmt.Errorf(\"dialing backend: %v\", err)\n\t}\n\t// fcgiBackend gets closed when response body is closed (see clientCloser)\n","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/probe/http/internal/fastcgi.go#L58-L94","documentation":"FastCGITransport.RoundTrip converts the incoming http.Request into a FastCGI environment (params) via buildEnv before talking to the backend. If that conversion fails, RoundTrip wraps the cause as \"building environment: %v\". It means the request could not be translated into a valid FastCGI parameter set.","triggerScenarios":"RoundTrip called on a FastCGI transport whose request has properties buildEnv cannot handle — typically a request URL the transport cannot resolve into a script name/path (e.g. missing or malformed URL path, unsupported scheme), or t.init()/state issues surfaced by buildEnv.","commonSituations":"Probing a PHP/FastCGI app where the probe request lacks a proper path (e.g. probing root with an empty URL); reverse-proxied requests whose Host/URL were rewritten; misconfigured FastCGI root/document settings inside the transport.","solutions":["Check the wrapped cause (%v) — the real error is inside buildEnv, and fix that condition.","Ensure the probe request URL has a valid path and host that map to the FastCGI app.","Verify the FastCGI transport's configured root/script filename matches the backend's document root.","Send a plain well-formed request (e.g. GET / with Host set) as a baseline test."],"exampleFix":"// before: malformed probe URL\nreq, _ := http.NewRequest(\"GET\", \"\", nil)\n// after\nreq, _ := http.NewRequest(\"GET\", \"http://app.local/index.php\", nil)\nresp, err := fcgiTransport.RoundTrip(req)","handlingStrategy":"try-catch","validationCode":"u, err := url.Parse(target)\nif err != nil || u.Path == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"probe target needs host and path, got %q\", target)\n}","typeGuard":null,"tryCatchPattern":"resp, err := fcgiTransport.RoundTrip(req)\nif err != nil && strings.Contains(err.Error(), \"building environment\") {\n    return fmt.Errorf(\"check FastCGI request URL/root config: %w\", err)\n}","preventionTips":["Probe requests with a full URL: scheme, host, and a real path.","Verify the FastCGI transport's root/script filename matches the backend docroot.","Read the wrapped cause — it names the exact buildEnv condition that failed."],"tags":["fastcgi","http-probe","request"],"backgroundTag":"fastcgi-env-build-failed","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}