dbt-labs/dbt-core · warning
Failed to create temp file
Error message
Failed to create temp file
What it means
Test panic from `NamedTempFile::new().expect("Failed to create temp file")` in `test_keypair_path_with_method_param`. It fires when the OS refuses to create the temporary key file the test needs (tempdir unavailable, permissions, disk full). The expect message is generic infrastructure, unrelated to keypair auth logic itself.
Source
Thrown at crates/dbt-auth/src/snowflake/mod.rs:1139
(snowflake::WAREHOUSE, "warehouse"),
(
snowflake::JWT_PRIVATE_KEY_PKCS8_VALUE,
expected_pem.as_str(),
),
(snowflake::AUTH_TYPE, "auth_jwt"),
(snowflake::APPLICATION_NAME, APP_NAME),
(snowflake::LOG_TRACING, "fatal"),
(snowflake::REQUEST_TIMEOUT, DEFAULT_REQUEST_TIMEOUT),
];
run_config_test(config, &expected);
}
#[test]
fn test_keypair_path_with_method_param() {
use std::io::Write;
use tempfile::NamedTempFile;
let mut tmp_file = NamedTempFile::new().expect("Failed to create temp file");
writeln!(tmp_file, "fake-private-key-data").unwrap();
let temp_path = tmp_file.path().to_str().expect("Valid UTF-8 path");
let mut config = base_config_without_password();
config.insert("method".into(), "keypair".into());
config.insert("private_key_path".into(), temp_path.into());
let expected = [
("user", "U"),
("password", ADBC_STUB_PASSWORD),
(snowflake::ACCOUNT, "A"),
(snowflake::ROLE, "role"),
(snowflake::WAREHOUSE, "warehouse"),
(snowflake::JWT_PRIVATE_KEY, temp_path),
(snowflake::AUTH_TYPE, "auth_jwt"),
(snowflake::APPLICATION_NAME, APP_NAME),
(snowflake::LOG_TRACING, "fatal"),
(snowflake::REQUEST_TIMEOUT, DEFAULT_REQUEST_TIMEOUT),
];View on GitHub (pinned to 0267ce9170)
Solutions
- Ensure TMPDIR points to a writable directory (e.g. export TMPDIR=/tmp or a project-local dir)
- Fix filesystem permissions on the temp directory for the test user
- Check disk space / inode and file-descriptor limits before rerunning the tests
Example fix
// before TMPDIR=/nonexistent cargo test -p dbt-auth // after export TMPDIR=$(mktemp -d) && cargo test -p dbt-auth test_keypair_path_with_method_param
Defensive patterns
Strategy: validation
Validate before calling
let tmp = std::env::temp_dir();
assert!(tmp.is_dir() && !tmp.read_only(), "temp dir unwritable: {:?}", tmp); Prevention
- Keep TMPDIR pointing at a writable directory in CI images
- Monitor disk space and fd limits on test runners
- Use mktemp-based TMPDIR in sandboxes
When it happens
Trigger: Running `cargo test -p dbt-auth` in an environment where `std::env::temp_dir()` is unwritable or `TMPDIR` points to a read-only/nonexistent path; sandboxed CI with restricted /tmp; low file-descriptor or disk limits.
Common situations: CI containers with no writable /tmp, restricted dev sandboxes, or a bad TMPDIR env var; macOS/Linux permission changes on /tmp.
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
AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07).
Data as JSON: /api/errors/525fe6447a93992e.
Report an issue: GitHub.