{"record":{"id":"fe3d577f86f1114c","repo":"golang/go","slug":"unrecognized-environment","errorCode":null,"errorMessage":"unrecognized environment","messagePattern":"unrecognized environment","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/cmd/internal/osinfo/os_js.go","lineNumber":24,"sourceCode":"\npackage osinfo\n\nimport (\n\t\"fmt\"\n\t\"syscall/js\"\n)\n\n// Version returns the OS version name/number.\nfunc Version() (string, error) {\n\t// Version detection on Wasm varies depending on the underlying runtime\n\t// (browser, node, etc), nor is there a standard via something like\n\t// WASI (see https://go.dev/issue/31105). For now, attempt a few simple\n\t// combinations for the convenience of reading logs at build.golang.org\n\t// and local development. It's not a goal to recognize all environments.\n\tif v, ok := node(); ok {\n\t\treturn \"Node.js \" + v, nil\n\t}\n\treturn \"\", fmt.Errorf(\"unrecognized environment\")\n}\n\nfunc node() (version string, ok bool) {\n\t// Try the https://nodejs.org/api/process.html#processversion API.\n\tp := js.Global().Get(\"process\")\n\tif p.IsUndefined() {\n\t\treturn \"\", false\n\t}\n\tv := p.Get(\"version\")\n\tif v.IsUndefined() {\n\t\treturn \"\", false\n\t}\n\treturn v.String(), true\n}\n","sourceCodeStart":6,"sourceCodeEnd":39,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/osinfo/os_js.go#L6-L39","documentation":"On the js/wasm target, osinfo.Version() makes a best-effort attempt to detect the runtime by checking for a global 'process' object with a 'version' property (Node.js). If that is absent, the environment is unrecognized. This is purely for log readability (e.g. build.golang.org) — it is not a hard failure path.","triggerScenarios":"Calling osinfo.Version() in a js/wasm build running in a JS environment without 'process.version' — e.g. a plain browser, a minimal JS shell, or an older engine.","commonSituations":"Running a Go js/wasm binary in a browser-only context, or in a custom/embedded JS runtime that does not expose Node's process API.","solutions":["Treat the error as informational; version detection is explicitly best-effort.","Run under Node.js if a version string is genuinely needed."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// v, err := osinfo.Version()\n// if err != nil {\n//     // js/wasm best-effort detection failed; degrade gracefully\n//     v = \"unknown (js/wasm)\"\n// }","preventionTips":["Treat osinfo.Version on js/wasm as best-effort for logging only.","Run under Node.js if a version string is genuinely required.","Do not gate behavior on a non-empty version under js/wasm."],"tags":["wasm","js","osinfo","version","best-effort"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}