gleam-lang/gleam · critical
hostname
Error message
hostname
What it means
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.
Source
Thrown at compiler-cli/src/hex/auth.rs:105
fn poll_for_oauth_next_step(
&mut self,
device_authorisation: &mut hexpm::OAuthDeviceAuthorisation,
) -> Result<hexpm::PollStep, Error> {
let request = device_authorisation.poll_token_request(&self.hex_config);
let response = self.runtime.block_on(self.http.send(request))?;
let next = device_authorisation
.poll_token_response(response)
.map_err(Error::hex)?;
Ok(next)
}
fn create_oauth_device_authorisation(
&mut self,
) -> Result<hexpm::OAuthDeviceAuthorisation, Error> {
// Create a recognisable name for the client, so folks can more easily understand which
// session is which in the Hex console.
// It is expected that we can always get the hostname.
let hostname = hostname::get().expect("hostname");
let client_name = format!("Gleam ({})", hostname.to_string_lossy());
let request = hexpm::oauth_device_authorisation_request(
HEX_OAUTH_CLIENT_ID,
&client_name,
&self.hex_config,
);
let response = self.runtime.block_on(self.http.send(request))?;
hexpm::oauth_device_authorisation_response(HEX_OAUTH_CLIENT_ID.to_string(), response)
.map_err(Error::hex)
}
fn encrypt_and_store_oauth_refresh_token(&mut self, tokens: &OAuthTokens) -> Result<(), Error> {
let path = paths::global_hexpm_oauth_credentials_path();
let local_password = self.get_local_password()?;
let encrypted_refresh_token =
encryption::encrypt_with_passphrase(tokens.refresh_token.as_bytes(), &local_password)
.map_err(|e| Error::FailedToEncryptLocalHexApiKey {View on GitHub (pinned to 7e623aa83d)
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
Example fix
# before: panics with 'hostname' in a stripped container docker run --rm -v $PWD:/app scratch-ci gleam hex authenticate # after: give the container a hostname (and /proc) docker run --rm --hostname gleam-ci -v $PWD:/app scratch-ci gleam hex authenticate
Defensive patterns
Strategy: validation
Validate before calling
# ensure a hostname is resolvable before OAuth login [ -n "$(hostname 2>/dev/null)" ] && [ -r /proc/sys/kernel/hostname ] \ && gleam hex authenticate \ || echo 'no usable hostname - set one (docker --hostname / hostnamectl) first'
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- stdin read_line
- Unable to start Tokio async runtime
- Unable to start Tokio async runtime
- `panic` expression evaluated.
- BEAM compiler instance exited: {status}
AI-assisted analysis of gleam-lang/gleam@7e623aa83d (2026-08-17).
Data as JSON: /api/errors/880af8ddaffff56b.
Report an issue: GitHub.