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

Fix stack exception name #855

Merged
merged 8 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ApplicationLogs/LogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static JObject TxLogToJson(Blockchain.ApplicationExecuted appExec)
}
catch (Exception ex)
{
stack.Add("error: " + ex);
stack.Add("error: " + ex.Message);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
stack.Add("error: " + ex.Message);
stack.Add(item.GetInterface<object>().GetType().Name);

Copy link
Member Author

Choose a reason for hiding this comment

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

This can break applicationlog getting the stack:
3e8148970abed45ba6ef0e98c4161c3
But you can see it's on-chain:
7723fcd8ecae99fdf1a629501952ada

}
}
trigger["stack"] = stack;
Expand Down Expand Up @@ -147,7 +147,7 @@ public static JObject BlockLogToJson(Block block, IReadOnlyList<Blockchain.Appli
}
catch (Exception ex)
{
stack.Add("error: " + ex);
stack.Add("error: " + ex.Message);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
stack.Add("error: " + ex.Message);
stack.Add(item.GetInterface<object>().GetType().Name);

Copy link
Contributor

Choose a reason for hiding this comment

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

The error means that there was a stackitem, but it can't be serialized and therefore can't be presented in JSON output. Replacing it with NULL or any other element (empty/string with a name) would be wrong because that's not what's on the stack. Proper stack item (like suggested) would be misinterpreted as a real output from the execution, it has to be some error string in case of serialization failure.

Copy link
Member

Choose a reason for hiding this comment

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

But the ones that can't be output to json are iterators (storage); at least what i have ran into (on testnet).

}
}
trigger["stack"] = stack;
Expand Down
2 changes: 1 addition & 1 deletion src/RpcServer/RpcServer.SmartContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private JObject GetInvokeResult(byte[] script, Signer[] signers = null, Witness[
}
catch (Exception ex)
{
stack.Add("error: " + ex);
stack.Add("error: " + ex.Message);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
stack.Add("error: " + ex.Message);
stack.Add(item.GetInterface<object>().GetType().Name);

Copy link
Member Author

Choose a reason for hiding this comment

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

In this way, it will throw exception directly but can't get result stack!
725922486f0147421b02d13395e875b
Compare to current code:
302dc02b1c0fea24c7e69980f02256f

}
}
json["stack"] = stack;
Expand Down