{"record":{"id":"63b52dc3a292a8af","repo":"joewalnes/websocketd","slug":"script-not-found","errorCode":null,"errorMessage":"script not found","messagePattern":"script not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"libwebsocketd/handler.go","lineNumber":24,"sourceCode":"package libwebsocketd\n\nimport (\n\t\"crypto/rand\"\n\t\"encoding/hex\"\n\t\"errors\"\n\t\"fmt\"\n\t\"net\"\n\t\"net/http\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strconv\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/gorilla/websocket\"\n)\n\nvar ErrScriptNotFound = errors.New(\"script not found\")\n\n// WebsocketdHandler is a single request information and processing structure, it handles WS requests out of all that daemon can handle (static, cgi, devconsole)\ntype WebsocketdHandler struct {\n\tserver *WebsocketdServer\n\n\tId string\n\t*RemoteInfo\n\t*URLInfo\n\tEnv []string\n\n\tcommand string\n}\n\n// NewWebsocketdHandler constructs the struct and parses all required things in it...\nfunc NewWebsocketdHandler(s *WebsocketdServer, req *http.Request, log *LogScope) (wsh *WebsocketdHandler, err error) {\n\twsh = &WebsocketdHandler{server: s, Id: generateId()}\n\tlog.Associate(\"id\", wsh.Id)\n","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/joewalnes/websocketd/blob/7a8683dc7f9778dc615945aaed2a8dc77290227b/libwebsocketd/handler.go#L6-L42","documentation":"ErrScriptNotFound is the sentinel error returned when websocketd cannot resolve a request path to an executable script. The handler requires the URL path to start with '/', the path must parse, and a matching script must exist under the configured --dir/scriptdir; any failure maps to this single sentinel.","triggerScenarios":"GetURLInfo (libwebsocketd/handler.go:140) when the request path is empty or does not begin with '/'; handler.go:154 when http url parsing of the path fails; serveWebSocket when no matching script file is found in the script directory.","commonSituations":"Requesting the bare root path '/' or an empty path; typo in the script name in the WebSocket URL; script placed outside the configured script directory; client connecting to a path that maps to a non-executable or missing file.","solutions":["Check the WebSocket URL path matches the script filename relative to the script directory","Verify the script exists and is executable in the directory passed via --dir","Ensure the client URL path starts with '/'","If mapping paths yourself, confirm the path is non-empty and begins with '/' before calling GetURLInfo"],"exampleFix":"// before\nws://host:8080/\n// after\nws://host:8080/myscript.js  (where ./myscript.js exists in the script dir)","handlingStrategy":"validation","validationCode":"// client-side check before connecting\nif (!path.startsWith('/')) throw new Error('path must start with /');\nconst res = await fetch('http://host:8080' + path, {method:'HEAD'});\nif (!res.ok) throw new Error('script not found at ' + path);","typeGuard":null,"tryCatchPattern":"const ws = new WebSocket(url);\nws.onerror = (e) => console.error('script not found — verify path and --dir:', url);","preventionTips":["Keep scripts in --dir and reference them by exact filename in the URL","Verify scripts are executable (chmod +x)","Smoke-test the URL path with a plain HTTP request before wiring the WebSocket client"],"tags":["websocket","handler","script-lookup"],"backgroundTag":"script-not-found","analyzedSha":"7a8683dc7f9778dc615945aaed2a8dc77290227b","analyzedAt":"2026-09-03T13:52:22.309Z","contentChangedAt":"2026-09-03T13:52:22.309Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}