gleam-lang/gleam · error · ErrorType
ErrorType::InvalidEndianness
Error message
ErrorType::InvalidEndianness
What it means
ErrorType::InvalidEndianness: endianness options (big/little/native) are only valid on segments whose type is int, float, utf16, utf16_codepoint, utf32, or utf32_codepoint. If a segment carries an endian option with an incompatible type (e.g. bytes, bits, utf8), the compiler rejects it at the endian option's location.
Solutions
- Remove the endianness option from bytes/bits/utf8 segments
- Change the segment's type to one that supports endianness (int, float, utf16, utf32, or their codepoints) if byte order matters
- Apply endianness per numeric field rather than to whole byte blobs
Example fix
// before <<blob:bytes-big>> // after <<blob:bytes>>
Defensive patterns
Strategy: validation
Validate before calling
// Endianness only applies to: int, float, utf16, utf32, utf16_codepoint, utf32_codepoint
fn endian_valid(type_str: String) -> Bool {
["int", "float", "utf16", "utf32", "utf16_codepoint", "utf32_codepoint"]
|> list.contains(type_str)
} Prevention
- Only attach big/little/native to numeric and utf16/utf32 segments
- bytes/bits/utf8 segments never take endianness — don't copy option chains between segment types
- If byte order matters for a blob, split it into sized int/float segments
When it happens
Trigger: Writing <<data:bytes-big>> or <<str:utf8-little>>; the final match in type_options finds categories.endian set while the segment's type is not one of the byte-order-compatible types.
Common situations: Applying endianness habitually to every segment; believing strings/bytes have byte-order semantics; copy-pasting an int segment's option list onto a bytes segment.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- ErrorType::ConflictingEndiannessOptions
- ErrorType::OptionNotSupportedForTarget
- ErrorType::ConflictingSignednessOptions
- ErrorType::ConflictingSizeOptions
- ErrorType::ConflictingUnitOptions
AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14).
Data as JSON: /api/errors/b895988bd515a1ac.
Report an issue: GitHub.
Appendix: source
Thrown at compiler-core/src/bit_array.rs:245
match categories {
SegmentOptionCategories {
type_:
None
| Some(
Int { .. }
| Utf16 { .. }
| Utf32 { .. }
| Utf16Codepoint { .. }
| Utf32Codepoint { .. }
| Float { .. },
),
..
} => {}
SegmentOptionCategories {
endian: Some(endian),
..
} => return err(ErrorType::InvalidEndianness, endian.location()),
_ => {}
}
// signed and unsigned can only be used with int types
match categories {
SegmentOptionCategories {
type_: None | Some(Int { .. }),
..
} => {}
SegmentOptionCategories {
type_: Some(opt),
signed: Some(sign),
..
} => {
return err(
ErrorType::SignednessUsedOnNonInt { type_: opt.label() },View on GitHub (pinned to 15b07c7830)