gleam-lang/gleam · error
hostname
Error message
hostname
What it means
Panic from `hostname::get().expect("hostname")` inside create_oauth_device_authorisation in compiler-cli/src/hex/auth.rs. The hostname crate could not determine the machine's hostname (gethostname failed or returned invalid data), so the client name for the OAuth device flow ("Gleam (<hostname>)") cannot be built and the process panics.
Solutions
- Set a proper hostname for the environment (e.g. `hostnameectl set-hostname name` or docker run --hostname).
- Ensure /etc/hostname and /proc are present and readable in the container/chroot.
- Fall back to a constant client name when the hostname is unavailable instead of panicking.
- Run the OAuth authentication flow on the developer's normal machine where the hostname is configured.
Example fix
// before
let hostname = hostname::get().expect("hostname");
let client_name = format!("Gleam ({})", hostname.to_string_lossy());
// after
let host = hostname::get().unwrap_or_else(|_| "unknown-host".into());
let client_name = format!("Gleam ({})", host.to_string_lossy()); Defensive patterns
Strategy: fallback
Validate before calling
// Pre-check hostname availability:
match hostname::get() { Ok(h) => println!("host: {}", h.to_string_lossy()), Err(_) => println!("hostname unavailable") } Type guard
fn hostname_available() -> bool { hostname::get().is_ok() } Try / catch
std::panic::catch_unwind(|| gleam_hex::authenticate())
.map_err(|_| anyhow::anyhow!("gleam auth panicked (hostname unavailable)"))?; Prevention
- Set a hostname in containers/chroots (docker run --hostname).
- Use unwrap_or with a default client name in library code.
- Keep /etc/hostname and /proc mounted and readable.
When it happens
Trigger: Starting the Hex OAuth device authorisation flow on a machine where hostname::get() errors: misconfigured /etc/hostname or /proc/sys/kernel/hostname, containers without a UTS namespace set, or unusual embedded platforms.
Common situations: Minimal Docker containers with no hostname configured, chroot environments lacking /proc or /etc/hostname, or Windows systems where GetComputerNameEx fails.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14).
Data as JSON: /api/errors/880af8ddaffff56b.
Report an issue: GitHub.
Appendix: 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(|error| Error::FailedToEncryptLocalHexApiKey {View on GitHub (pinned to 15b07c7830)