gleam-lang/gleam · error

Failed to take ownership of sourcemap builder

Error message

Failed to take ownership of sourcemap builder

What it means

Error "Failed to take ownership of sourcemap builder" thrown in gleam-lang/gleam.

Source

Thrown at compiler-core/src/javascript.rs:1360

    pub stdlib_package: StdlibPackage,
    pub path: &'a Utf8Path,
    pub project_root: &'a Utf8Path,
}

pub fn module(config: ModuleConfig<'_>) -> (String, Option<SourceMap>) {
    let (output, sourcemap_builder) = {
        let arena = DocumentArena::new();
        let mut generator = Generator::new(config);
        let document = generator.compile(&arena).to_pretty_string(80);
        let builder = generator.source_map_builder;
        (document, builder)
    };

    let source_map = sourcemap_builder.map(|builder| {
        // We have completed the generation of the module, so we can now take ownership
        // of the builder.
        Rc::try_unwrap(builder)
            .expect("Failed to take ownership of sourcemap builder")
            .into_inner()
            .0
            .into_sourcemap()
    });
    (output, source_map)
}

pub fn ts_declaration(module: &TypedModule) -> String {
    let arena = DocumentArena::new();
    let document = typescript::TypeScriptGenerator::new(module).compile(&arena);
    document.to_pretty_string(80)
}

fn create_cursor_position_observer<'a, 'doc>(
    arena: &'doc DocumentArena<'a, 'doc>,
    builder: &Option<Rc<RefCell<DebugIgnore<sourcemap::SourceMapBuilder>>>>,
    line_numbers: &LineNumbers,
    start_index: u32,

View on GitHub (pinned to 7e623aa83d)

When it happens

Trigger: Thrown at compiler-core/src/javascript.rs:1360 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of gleam-lang/gleam@7e623aa83d (2026-08-17). Data as JSON: /api/errors/7b16e69afb0ffdd6. Report an issue: GitHub.