apple/pkl · error · PklException
Failed to write to $depsFile: ${e.message}
Error message
Failed to write to $depsFile: ${e.message} What it means
Thrown by CliProjectResolver.doRun when writing the generated PklProjectDependencies file (PklProjectDependencies.pem deps file next to the PklProject) fails with an IOException. `pkl project resolve` computes the dependency graph and persists it to disk; if the file cannot be opened or written, the resolver wraps the IOException in a PklException with this message, which includes the deps file path and the underlying IOException message.
Source
Thrown at pkl-cli/src/main/kotlin/org/pkl/cli/CliProjectResolver.kt:56
PackageResolver.getInstance(
SecurityManagers.standard(
allowedModules,
allowedResources,
SecurityManagers.defaultTrustLevels,
rootDir,
),
httpClient,
moduleCacheDir,
)
val dependencies = ProjectDependenciesResolver(project, packageResolver, errWriter).resolve()
val depsFile =
projectFile.parent.resolve(ProjectDependenciesManager.PKL_PROJECT_DEPS_FILENAME).toFile()
try {
depsFile.outputStream().use { dependencies.writeTo(it) }
consoleWriter.appendLine(depsFile.toString())
consoleWriter.flush()
} catch (e: IOException) {
throw PklException("Failed to write to $depsFile: ${e.message}", e)
}
}
}
}
View on GitHub (pinned to f3efcbfc9b)
Solutions
- Check and fix write permissions on the project directory and any existing PklProjectDependencies file (e.g. chmod/chown)
- Remove the stale deps file if it is owned by another user or immutable
- Ensure the filesystem is writable (not mounted read-only) and has free disk space
- Re-run `pkl project resolve`
Defensive patterns
Strategy: try-catch
Try / catch
try { resolveProject() } catch (PklException e) { if (e.getMessage().startsWith("Failed to write to")) handleUnwritableDepsFile(); else throw e; } Prevention
- Ensure the project dir is writable before running resolve
- Don't run as root in shared checkouts; fix ownership of generated deps files
When it happens
Trigger: Running `pkl project resolve` when the target deps file cannot be written: read-only filesystem or directory, missing write permissions, the path is a directory instead of a file, or disk full.
Common situations: Running inside a read-only container or CI workspace; file owned by another user after running as root earlier; the project directory was made immutable; NFS/permissions issues in shared dev environments.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- ioErrorWritingTestOutputFile
- ioErrorReadingTestOutputFile
- ioErrorLoadingModule
- ioErrorLoadingModule
- I/O error writing file `$outputFile`. Cause: ${e.message}
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/b9ead56b29506cc1.
Report an issue: GitHub.