Skip to content

Commit a7caf35

Browse files
andrewjcgfacebook-github-bot
authored andcommitted
Add context for workspace env var resolution errors (meta-pytorch#879)
Summary: Pull Request resolved: meta-pytorch#879 Previously, if the env var we read from to locate the workspace isn't set, we'd just get a cryptic `NotPresent` error back from the client, with not clue as to where it came from. Add context to make it very clear. Reviewed By: highker Differential Revision: D80267336 fbshipit-source-id: 844fe3d2c7be622ddcb3eef3a072ebf6635dbd30
1 parent 228395c commit a7caf35

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

monarch_hyperactor/src/code_sync/rsync.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ impl Handler<RsyncMessage> for RsyncActor {
358358
}: RsyncMessage,
359359
) -> Result<(), anyhow::Error> {
360360
let res = async {
361-
let workspace = workspace.resolve()?;
361+
let workspace = workspace
362+
.resolve()
363+
.context("resolving workspace location")?;
362364
let (connect_msg, completer) = Connect::allocate(cx.self_id().clone(), cx);
363365
connect.send(cx, connect_msg)?;
364366
let (listener, mut stream) = try_join!(

monarch_hyperactor/src/code_sync/workspace.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use std::path::PathBuf;
1010

11+
use anyhow::Context;
1112
use anyhow::Result;
1213
use serde::Deserialize;
1314
use serde::Serialize;
@@ -22,7 +23,9 @@ impl WorkspaceLocation {
2223
pub fn resolve(&self) -> Result<PathBuf> {
2324
Ok(match self {
2425
WorkspaceLocation::Constant(p) => p.clone(),
25-
WorkspaceLocation::FromEnvVar(v) => PathBuf::from(std::env::var(v)?),
26+
WorkspaceLocation::FromEnvVar(v) => PathBuf::from(
27+
std::env::var_os(v).with_context(|| format!("workspace env var not set: {}", v))?,
28+
),
2629
})
2730
}
2831
}

0 commit comments

Comments
 (0)