{"record":{"id":"880af8ddaffff56b","repo":"gleam-lang/gleam","slug":"hostname","errorCode":null,"errorMessage":"hostname","messagePattern":"hostname","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler-cli/src/hex/auth.rs","lineNumber":105,"sourceCode":"    fn poll_for_oauth_next_step(\n        &mut self,\n        device_authorisation: &mut hexpm::OAuthDeviceAuthorisation,\n    ) -> Result<hexpm::PollStep, Error> {\n        let request = device_authorisation.poll_token_request(&self.hex_config);\n        let response = self.runtime.block_on(self.http.send(request))?;\n        let next = device_authorisation\n            .poll_token_response(response)\n            .map_err(Error::hex)?;\n        Ok(next)\n    }\n\n    fn create_oauth_device_authorisation(\n        &mut self,\n    ) -> Result<hexpm::OAuthDeviceAuthorisation, Error> {\n        // Create a recognisable name for the client, so folks can more easily understand which\n        // session is which in the Hex console.\n        // It is expected that we can always get the hostname.\n        let hostname = hostname::get().expect(\"hostname\");\n        let client_name = format!(\"Gleam ({})\", hostname.to_string_lossy());\n\n        let request = hexpm::oauth_device_authorisation_request(\n            HEX_OAUTH_CLIENT_ID,\n            &client_name,\n            &self.hex_config,\n        );\n        let response = self.runtime.block_on(self.http.send(request))?;\n        hexpm::oauth_device_authorisation_response(HEX_OAUTH_CLIENT_ID.to_string(), response)\n            .map_err(Error::hex)\n    }\n\n    fn encrypt_and_store_oauth_refresh_token(&mut self, tokens: &OAuthTokens) -> Result<(), Error> {\n        let path = paths::global_hexpm_oauth_credentials_path();\n        let local_password = self.get_local_password()?;\n        let encrypted_refresh_token =\n            encryption::encrypt_with_passphrase(tokens.refresh_token.as_bytes(), &local_password)\n                .map_err(|e| Error::FailedToEncryptLocalHexApiKey {","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/gleam-lang/gleam/blob/7e623aa83da3776faee50ca4ab9a6c40124acd95/compiler-cli/src/hex/auth.rs#L87-L123","documentation":"During Hex OAuth device login, `create_oauth_device_authorisation` (compiler-cli/src/hex/auth.rs:105) builds a recognizable client name `\"Gleam (<hostname>)\"` for the Hex console. It calls `hostname::get().expect(\"hostname\")`, explicitly assuming gethostname can never fail (the comment says so). If the OS cannot return a hostname, the login flow panics before any HTTP request is sent.","triggerScenarios":"Running `gleam hex authenticate` (or the first-run OAuth login behind `gleam publish`) in an environment where hostname lookup fails: containers without /proc mounted (hostname::get reads /proc/sys/kernel/hostname on Linux), chroot/namespaces with an unusable hostname, or libc-level gethostname(2) failures in restricted sandboxes.","commonSituations":"Heavily stripped scratch/distroless containers; minimal VMs whose init never sets a hostname; unusual embedded or sandbox runtimes. Normal desktops, standard Docker (always has a hostname), and CI runners do not hit this.","solutions":["Set an explicit hostname: `docker run --hostname gleam-ci ...` or `hostnamectl set-hostname build01` / `hostname build01`","Ensure /proc is mounted and readable inside the container/chroot","Run `gleam hex authenticate` once on a normal machine and copy the stored credentials (the Hex API key under ~/.config/gleam) into the constrained environment","If it still panics, report it upstream — the code treats 'hostname always available' as an invariant, so this path is untested"],"exampleFix":"# before: panics with 'hostname' in a stripped container\ndocker run --rm -v $PWD:/app scratch-ci gleam hex authenticate\n\n# after: give the container a hostname (and /proc)\ndocker run --rm --hostname gleam-ci -v $PWD:/app scratch-ci gleam hex authenticate","handlingStrategy":"validation","validationCode":"# ensure a hostname is resolvable before OAuth login\n[ -n \"$(hostname 2>/dev/null)\" ] && [ -r /proc/sys/kernel/hostname ] \\\n  && gleam hex authenticate \\\n  || echo 'no usable hostname - set one (docker --hostname / hostnamectl) first'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always start containers with an explicit hostname (`--hostname`)","Keep /proc mounted in minimal images used for gleam network commands","Pre-authenticate elsewhere and mount the stored credentials instead of running OAuth in stripped environments"],"tags":["gleam","hex","oauth","hostname","authentication","container"],"backgroundTag":"hostname-lookup-failed","analyzedSha":"7e623aa83da3776faee50ca4ab9a6c40124acd95","analyzedAt":"2026-08-17T00:07:02.091Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}