Skip to content

Simplify error handling in node code - #4760

Open
timon-schelling wants to merge 2 commits into
masterfrom
node-error-improvements
Open

timon-schelling wants to merge 2 commits into
masterfrom
node-error-improvements

Conversation

@timon-schelling

@timon-schelling timon-schelling commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Allow nodes to return any impl Into<NodeError> and allow async nodes to return error and fallback.

#[node_macro::node(...)]
fn parse(_: impl Ctx, text: Item<String>) -> Result<Item<f64>, ParseFloatError> {
	Ok(Item::new_from_element(text.element().parse()?))
}

#[node_macro::node(...)]
async fn load(_: impl Ctx, hash: Item<ResourceHash>) -> Result<Item<Resource>, std::io::Error> {
	let resource = storage.load(*hash.element()).await.ok_or_else(|| std::io::Error::other("Not in storage"))?;
	Ok(Item::new_from_element(resource))
}

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 4 files

Confidence score: 3/5

  • poll.rs removes std::error::Error from the public NodeError type, which can break downstream code that uses it as a standard error or propagates it with ?. Preserve the Error implementation or account for this API break.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="node-graph/libraries/core-types/src/poll.rs">

<violation number="1" location="node-graph/libraries/core-types/src/poll.rs:120">
P2: This replacement removes `std::error::Error` from the public `NodeError` type, so downstream code can no longer use it as `Box<dyn Error>`, propagate it with `?` into standard-error results, or inspect its `source()` chain. Keep the `Error` implementation and expose this conversion through a differently named constructor or method, since the blanket `From<E>` cannot coexist with that implementation.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

impl Error for NodeError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
self.error.source()
impl<E: Error + Send + Sync + 'static> From<E> for NodeError {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: This replacement removes std::error::Error from the public NodeError type, so downstream code can no longer use it as Box<dyn Error>, propagate it with ? into standard-error results, or inspect its source() chain. Keep the Error implementation and expose this conversion through a differently named constructor or method, since the blanket From<E> cannot coexist with that implementation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At node-graph/libraries/core-types/src/poll.rs, line 120:

<comment>This replacement removes `std::error::Error` from the public `NodeError` type, so downstream code can no longer use it as `Box<dyn Error>`, propagate it with `?` into standard-error results, or inspect its `source()` chain. Keep the `Error` implementation and expose this conversion through a differently named constructor or method, since the blanket `From<E>` cannot coexist with that implementation.</comment>

<file context>
@@ -117,9 +117,9 @@ impl std::fmt::Display for NodeError {
-impl Error for NodeError {
-	fn source(&self) -> Option<&(dyn Error + 'static)> {
-		self.error.source()
+impl<E: Error + Send + Sync + 'static> From<E> for NodeError {
+	fn from(error: E) -> Self {
+		Self::new(error)
</file context>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@TrueDoctor This is a tradeoff, we could do something like NodeError::from_std(<impl Error>) instead. I think I like this better for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how is this done in crates like anyhow?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They also impl From<std::Error> and then do the rest with deref I think.

This branch was successfully deployed

1 active deployment
graphite-dev (Preview) — 2f9f683e Deployed Oct 20, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants