Skip to content

Commit

Permalink
Include internal_message in all errors for local dev (#1522)
Browse files Browse the repository at this point in the history
  • Loading branch information
eandre authored Oct 25, 2024
1 parent c225d35 commit 0ab8182
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cli/daemon/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,11 @@ const gracefulShutdownTime = 10 * time.Second
func (r *Run) StartProcGroup(params *StartProcGroupParams) (p *ProcGroup, err error) {
pid := GenID()

userEnv := append([]string{"ENCORE_RUNTIME_LOG=error"}, params.Environ...)
userEnv := append([]string{
"ENCORE_RUNTIME_LOG=error",
// Always include internal messages when developing locally.
"ENCORE_INCLUDE_INTERNAL_MESSAGE_ERRORS=1",
}, params.Environ...)

daemonProxyAddr, err := netip.ParseAddrPort(strings.ReplaceAll(r.ListenAddr, "localhost", "127.0.0.1"))
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions runtimes/core/src/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ pub struct Error {
#[derive(Debug)]
pub struct ExternalError<'a>(&'a Error);

/// Cached environment variable for whether to include internal message in all errors.
static ENCORE_INCLUDE_INTERNAL_MESSAGE_ERRORS: once_cell::sync::Lazy<bool> =
once_cell::sync::Lazy::new(|| {
std::env::var("ENCORE_INCLUDE_INTERNAL_MESSAGE_ERRORS")
.map(|v| !v.is_empty() && v != "0")
.unwrap_or(false)
});

impl Serialize for ExternalError<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -32,6 +40,11 @@ impl Serialize for ExternalError<'_> {
error.serialize_field("code", &self.0.code)?;
error.serialize_field("message", &self.0.message)?;
error.serialize_field("details", &self.0.details)?;

// Include internal message even in external errors iff the environment variable is set.
if *ENCORE_INCLUDE_INTERNAL_MESSAGE_ERRORS {
error.serialize_field("internal_message", &self.0.internal_message)?;
}
error.end()
}
}
Expand Down

0 comments on commit 0ab8182

Please sign in to comment.