gleam-lang/gleam · error
unimplemented
Error message
unimplemented
What it means
The in-memory filesystem used for compiler testing/sandboxing (`compiler-core/src/io/memory.rs:152`) implements `copy_dir` as an explicit stub that panics with `"unimplemented"`. The `FileSystemReader`/writer trait allows directory copying, but the in-memory implementation never implemented it; any code path invoking it against the memory FS aborts immediately.
Solutions
- Implement `copy_dir` in the memory FS: recursively `mkdir` the destination and `copy` each file via `read_dir`/`copy`.
- Avoid the memory FS for operations needing directory copies; use the real filesystem wrapper instead.
- Refactor the caller to copy files individually instead of relying on `copy_dir`.
- Track/upvote the TODO in the source; until then treat memory-FS `copy_dir` as unavailable.
Example fix
// before
fn copy_dir(&self, _: &Utf8Path, _: &Utf8Path) -> Result<(), Error> {
panic!("unimplemented") // TODO
}
// after
fn copy_dir(&self, from: &Utf8Path, to: &Utf8Path) -> Result<(), Error> {
self.mkdir(to)?;
for entry in self.read_directory(from)? {
let f = from.join(&entry);
let t = to.join(&entry);
if self.is_directory(&f) { self.copy_dir(&f, &t)?; } else { self.copy(&f, &t)?; }
}
Ok(())
} Defensive patterns
Strategy: fallback
Validate before calling
// avoid copy_dir on the in-memory FS
if fs.supports_copy_dir() { fs.copy_dir(from, to)?; } else { copy_files_individually(...)?; } Try / catch
// no catchable error: this is a panic; feature-detect instead
if is_memory_fs(fs) { /* implement manual recursive copy */ } Prevention
- Do not use the in-memory filesystem for operations requiring directory copies
- Feature-detect the FS backend capability before calling copy_dir
- Contribute an implementation for the TODO stub
When it happens
Trigger: Any operation that calls `copy_dir` on an `in-memory::FileSystem` — e.g. tests or tooling that use the memory FS and trigger a recursive directory copy (such as copying a project directory during build/packaging logic exercised in tests).
Common situations: Gleam compiler contributors running tests that exercise directory-copy code paths with the in-memory FS; library consumers using `gleam-core` with the memory FS backend for build operations that require `copy_dir`.
Related errors
- channel buffer write
- Final result error writing
- joining_lsp_threads
- Writing warning to stderr
- aliased non constant value
AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14).
Data as JSON: /api/errors/6210301ae5d73d82.
Report an issue: GitHub.
Appendix: source
Thrown at compiler-core/src/io/memory.rs:152
// Remove any files in the directory
while let Some(file) = files
.keys()
.find(|file| file.as_path() != root && file.starts_with(path))
{
let file = file.clone();
let _ = files.remove(&file);
}
Ok(())
}
fn copy(&self, from: &Utf8Path, to: &Utf8Path) -> Result<(), Error> {
self.write_bytes(to, &self.read_bytes(from)?)
}
fn copy_dir(&self, _: &Utf8Path, _: &Utf8Path) -> Result<(), Error> {
panic!("unimplemented") // TODO
}
fn mkdir(&self, path: &Utf8Path) -> Result<(), Error> {
// Traverse ancestors from parent to root.
// Create each missing ancestor.
for ancestor in path.ancestors() {
if ancestor == "" {
// Ignore the final ancestor of a relative path.
continue;
}
// Ensure we don't overwrite an existing file.
// We can ignore existing directories though.
let mut files = self.files.deref().borrow_mut();
if files.get(ancestor).is_some_and(|f| !f.is_directory()) {
return Err(Error::FileIo {
kind: FileKind::Directory,
action: FileIoAction::Create,
path: ancestor.to_path_buf(),View on GitHub (pinned to 15b07c7830)