Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite error message when Pantsd is shut down during run #12107

Merged
merged 9 commits into from
May 24, 2021
8 changes: 3 additions & 5 deletions src/python/pants/bin/remote_pants_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from pants.base.exiter import ExitCode
from pants.engine.internals import native_engine
from pants.engine.internals.native_engine import NailgunConnectionException
from pants.engine.internals.native_engine import PantsdConnectionException
from pants.nailgun.nailgun_protocol import NailgunProtocol
from pants.option.global_options import GlobalOptions
from pants.option.options_bootstrapper import OptionsBootstrapper
Expand Down Expand Up @@ -132,10 +132,8 @@ def _connect_and_execute(self, pantsd_handle: PantsDaemonClient.Handle) -> ExitC
return native_engine.nailgun_client_create(executor, port).execute(
command, args, modified_env
)

# NailgunConnectionException represents a failure connecting to pantsd, so we retry
# up to the retry limit.
except NailgunConnectionException as e:
# Retry if we failed to connect to Pantsd.
except PantsdConnectionException as e:
if attempt > retries:
raise self.Fallback(e)

Expand Down
5 changes: 4 additions & 1 deletion src/python/pants/engine/internals/native_engine.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ class PyStubCAS:
class PyStdioDestination:
pass

class NailgunConnectionException(Exception):
class PantsdConnectionException(Exception):
pass

class PantsdClientException(Exception):
pass

class PollTimeout(Exception):
Expand Down
9 changes: 3 additions & 6 deletions src/rust/engine/nailgun/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ pub async fn client_execute(
let socket = TcpStream::connect((Ipv4Addr::new(127, 0, 0, 1), port))
.await
.map_err(|err| {
NailgunClientError::PreConnect(format!(
"Nailgun client error connecting to localhost: {}",
err
))
NailgunClientError::PreConnect(format!("Failed to connect to localhost: {}", err))
})?;

let mut child = nails::client::handle_connection(config, socket, command, async {
Expand All @@ -155,7 +152,7 @@ pub async fn client_execute(
stdin_read
})
.await
.map_err(|err| NailgunClientError::PreConnect(format!("Failed to start remote task: {}", err)))?;
.map_err(|err| NailgunClientError::PreConnect(format!("Failed to start: {}", err)))?;
Comment on lines -158 to +155
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this wording should be. Really, it's a failure to start the Pants command, meaning sending the sys.argv to Nailgun like ./pants lint ::.


handle_client_output(
child.output_stream.take().unwrap(),
Expand All @@ -167,7 +164,7 @@ pub async fn client_execute(
let exit_code: ExitCode = child
.wait()
.await
.map_err(|err| NailgunClientError::PostConnect(format!("Nailgun client error: {}", err)))?;
.map_err(|err| NailgunClientError::PostConnect(format!("Failed during execution: {}", err)))?;

Ok(exit_code.0)
}
19 changes: 8 additions & 11 deletions src/rust/engine/src/externs/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,22 @@ use crate::{
mod testutil;

py_exception!(native_engine, PollTimeout);
py_exception!(native_engine, NailgunConnectionException);
py_exception!(native_engine, NailgunClientException);
py_exception!(native_engine, PantsdConnectionException);
py_exception!(native_engine, PantsdClientException);

py_module_initializer!(native_engine, |py, m| {
m.add(py, "PollTimeout", py.get_type::<PollTimeout>())
.unwrap();

m.add(
py,
"NailgunClientException",
py.get_type::<NailgunClientException>(),
"PantsdClientException",
py.get_type::<PantsdClientException>(),
)?;
m.add(
py,
"NailgunConnectionException",
py.get_type::<NailgunConnectionException>(),
"PantsdConnectionException",
py.get_type::<PantsdConnectionException>(),
)?;

m.add(py, "default_cache_path", py_fn!(py, default_cache_path()))?;
Expand Down Expand Up @@ -700,11 +700,8 @@ py_class!(class PyNailgunClient |py| {
args,
env_list,
)).map(|code| code.to_py_object(py)).map_err(|e| match e{
NailgunClientError::PreConnect(err_str) => PyErr::new::<NailgunConnectionException, _>(py, (err_str,)),
NailgunClientError::PostConnect(s) => {
let err_str = format!("Nailgun client error: {:?}", s);
PyErr::new::<NailgunClientException, _>(py, (err_str,))
},
NailgunClientError::PreConnect(err_str) => PyErr::new::<PantsdConnectionException, _>(py, (err_str,)),
NailgunClientError::PostConnect(err_str) => PyErr::new::<PantsdClientException, _>(py, (err_str,)),
NailgunClientError::BrokenPipe => {
PyErr::new::<exc::BrokenPipeError, _>(py, NoArgs)
}
Expand Down