-
Notifications
You must be signed in to change notification settings - Fork 43
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
Improve the readability of stack traces #1458
Comments
Some examples of panic outputs in different environments for inspiration are below. They use very simple inputs, so their utility may be limited, but maybe we can learn something from them. I also understand that the diagnostic events are not stack traces, and they don't point to code, but developers sort of treat them as similar, as a way to understand where the program was when something went wrong. Rustfn main() {
f1(1)
}
fn f1(i: u32) {
f2()
}
fn f2() {
f3()
}
fn f3() {
panic!("oh no")
}
Gopackage main
func main() {
f1(1)
}
func f1(i int) {
f2()
}
func f2() {
f3()
}
func f3() {
panic("oh no")
}
Nodefunction f1(i) {
f2();
}
function f2() {
f3();
}
function f3() {
throw "oh no";
}
f1(1);
Bunfunction f1(i) {
f2();
}
function f2() {
f3();
}
function f3() {
throw "oh no";
}
f1(1);
Denofunction f1(i: u32) {
f2();
}
function f2() {
f3();
}
function f3() {
throw "oh no";
}
f1(1);
Pythondef f1(i):
f2()
def f2():
f3()
def f3():
raise Exception("oh no")
f1(1)
Rubydef f1(i)
f2()
end
def f2()
f3()
end
def f3()
raise "oh no"
end
f1(1)
Javapublic class Main {
public static void main(String[] args) {
f1(1);
}
public static void f1(int i) {
f2();
}
public static void f2() {
f3();
}
public static void f3() {
throw new RuntimeException("oh no");
}
}
.NETusing System;
public class Program
{
public static void Main()
{
f1(1);
}
public static void f1(int i) {
f2();
}
public static void f2() {
f3();
}
public static void f3() {
throw new Exception("oh no");
}
}
Swiftimport Foundation
func f1(i: Int) {
f2();
}
func f2() {
f3();
}
func f3() {
fatalError("oh no");
}
f1(i: 1);
Zigpub fn main() !void {
f1(1);
}
fn f1(_: i32) void {
f2();
}
fn f2() void {
f3();
}
fn f3() void {
@panic("oh no");
}
|
My main interest is mostly just readability. So adding more whitespace and line breaks would go a long way towards legibility. e.g. Event log (newest first):
0: [Diagnostic Event]
topics:[error, Error(Auth, InvalidAction)],
data:"escalating error to panic"
1: [Diagnostic Event]
topics:[error, Error(Auth, InvalidAction)],
data:["contract call failed", add, [[Policy, [CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4], [Temporary], [Admin]]]]
2: [Failed Diagnostic Event (not emitted)]
contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM,
topics:[error, Error(Auth, InvalidAction)], data:"caught error from function"
3: [Failed Diagnostic Event (not emitted)]
contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM,
topics:[error, Error(Auth, InvalidAction)],
data:"escalating error to panic"
4: [Failed Diagnostic Event (not emitted)]
contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM,
topics:[error, Error(Auth, InvalidAction)],
data:["Unauthorized function call for address", CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM]
5: [Diagnostic Event]
topics:[fn_call, Bytes(0000000000000000000000000000000000000000000000000000000000000001), add],
data:[Policy, [CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4], [Temporary], [Admin]]
6: [Diagnostic Event]
contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM,
topics:[fn_return, add],
data:Void
7: [Contract Event]
contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM,
topics:[sw_v1, add, [Ed25519, [Bytes(a1738d72617d88f775693c9b9033d8bbb99d127ea9ac0f04940dd090350c5b4e)]]],
data:[Ed25519, [Admin]]
8: [Diagnostic Event]
topics:[fn_call, Bytes(0000000000000000000000000000000000000000000000000000000000000001), add],
data:[Ed25519, [Bytes(a1738d72617d88f775693c9b9033d8bbb99d127ea9ac0f04940dd090350c5b4e)], [Persistent], [Admin]]
9: [Diagnostic Event]
contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM,
topics:[fn_return, add],
data:Void
10: [Contract Event]
contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM,
topics:[sw_v1, add, [Secp256r1, [Bytes(f3f8d84ae2da5566c4a70e977c2a49888a66bb8c)]]],
data:[Secp256r1, [Bytes(04a38ef5f2713768bd3480eeceaec2b10464a1f3b1ff0a3539c2cd2dd00a83a75d2c7b7e5fdbcfe6af5a602979c57fb44aeca0003cb9d3ae85d7c8d0e633d25ed6)], [Admin]]
11: [Diagnostic Event]
topics:[fn_call, Bytes(0000000000000000000000000000000000000000000000000000000000000001), add],
data:[Secp256r1, [Bytes(f3f8d84ae2da5566c4a70e977c2a49888a66bb8c)], [Bytes(04a38ef5f2713768bd3480eeceaec2b10464a1f3b1ff0a3539c2cd2dd00a83a75d2c7b7e5fdbcfe6af5a602979c57fb44aeca0003cb9d3ae85d7c8d0e633d25ed6)], [Persistent], [Admin]] You could further break up arrays by comma if you wanted to but that would start to make stack traces very very long. |
Idk if we have the ability to color anything but highlighting actual error messages would also be really nice. e.g. from above these are really the meat of the error |
Great to see this being worked on, thank you! 😃 I have posted that example on twitter in Tomer's thread. Thank you again for your reply. The task becomes very challenging if you are trying to do cross-contract calls. I understand a bit how that works (I helped polish the doc on that part during the last bounty) and once you get how to call another contract from yours, the next challenge becomes: how to read these errors. Here is an example on my project. I am calling Soroban Domains to register a domain. If I deliberately change that line and use a non valid TLD (these 3 bytes write xlm) Then it will result in this panic. Trace
/Users/tupui/.cargo/bin/cargo test --color=always --profile test --workspace --no-fail-fast --config env.RUSTC_BOOTSTRAP=\"1\" -- --format=json -Z unstable-options --show-output
Testing started at 23:43 ...
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.07s
Running unittests src/lib.rs (target/debug/deps/versioning-0b6e8f3c06df1343)
HostError: Error(Contract, #4)
Event log (newest first):
0: [Diagnostic Event] topics:[error, Error(Contract, #4)], data:"escalating error to panic"
1: [Diagnostic Event] topics:[error, Error(Contract, #4)], data:["contract call failed", register, [CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, "tansu", [CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5], "github.com/file.toml", "2ef4f49fdd8fa9dc463f1f06a094c26b88710990", CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V]]
2: [Failed Diagnostic Event (not emitted)] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, topics:[error, Error(Contract, #4)], data:"caught error from function"
3: [Failed Diagnostic Event (not emitted)] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, topics:[error, Error(Contract, #4)], data:"escalating error to panic"
4: [Failed Diagnostic Event (not emitted)] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, topics:[error, Error(Contract, #4)], data:["contract call failed", set_record, [Bytes(74616e7375), Bytes(786c), CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, 31536000]]
5: [Failed Diagnostic Event (not emitted)] contract:CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V, topics:[log], data:["VM call trapped with HostError", set_record, Error(Contract, #4)]
6: [Failed Diagnostic Event (not emitted)] contract:CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V, topics:[error, Error(Contract, #4)], data:"escalating error to VM trap from failed host function call: fail_with_error"
7: [Failed Diagnostic Event (not emitted)] contract:CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V, topics:[error, Error(Contract, #4)], data:["failing with contract error", 4]
8: [Failed Diagnostic Event (not emitted)] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, topics:[fn_call, Bytes(54ca65a58200bfffb708756d19fd134e1677063f85bb87e0c7a54abb480d375c), set_record], data:[Bytes(74616e7375), Bytes(786c), CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, 31536000]
9: [Failed Diagnostic Event (not emitted)] contract:CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V, topics:[fn_return, record], data:Void
10: [Failed Diagnostic Event (not emitted)] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, topics:[fn_call, Bytes(54ca65a58200bfffb708756d19fd134e1677063f85bb87e0c7a54abb480d375c), record], data:[Record, Bytes(2324dc49faf83ad010cee02118b8244566e3f9065e94a2694a8f57e377f7275c)]
11: [Diagnostic Event] topics:[fn_call, Bytes(0000000000000000000000000000000000000000000000000000000000000006), register], data:[CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, "tansu", [CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5], "github.com/file.toml", "2ef4f49fdd8fa9dc463f1f06a094c26b88710990", CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V]
12: [Diagnostic Event] contract:CCABDO7UZXYE4W6GVSEGSNNZTKSLFQGKXXQTH6OX7M7GKZ4Z6CUJNGZN, topics:[fn_return, mint], data:Void
13: [Contract Event] contract:CCABDO7UZXYE4W6GVSEGSNNZTKSLFQGKXXQTH6OX7M7GKZ4Z6CUJNGZN, topics:[mint, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, "aaa:GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJXFF"], data:10000000000000000
14: [Diagnostic Event] topics:[fn_call, Bytes(8011bbf4cdf04e5bc6ac886935b99aa4b2c0cabde133f9d7fb3e656799f0a896), mint], data:[CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, 10000000000000000]
15: [Diagnostic Event] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, topics:[fn_return, init], data:Void
16: [Diagnostic Event] topics:[fn_call, Bytes(0000000000000000000000000000000000000000000000000000000000000006), init], data:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM
17: [Diagnostic Event] contract:CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V, topics:[fn_return, init], data:Void
18: [Diagnostic Event] topics:[fn_call, Bytes(54ca65a58200bfffb708756d19fd134e1677063f85bb87e0c7a54abb480d375c), init], data:[CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4, 100, CCABDO7UZXYE4W6GVSEGSNNZTKSLFQGKXXQTH6OX7M7GKZ4Z6CUJNGZN, 31536000, [Bytes(786c6d), Bytes(7374656c6c6172), Bytes(77616c6c6574), Bytes(64616f)]]
19: [Diagnostic Event] contract:CCABDO7UZXYE4W6GVSEGSNNZTKSLFQGKXXQTH6OX7M7GKZ4Z6CUJNGZN, topics:[fn_return, set_admin], data:Void
20: [Contract Event] contract:CCABDO7UZXYE4W6GVSEGSNNZTKSLFQGKXXQTH6OX7M7GKZ4Z6CUJNGZN, topics:[set_admin, GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJXFF, "aaa:GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJXFF"], data:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M
21: [Diagnostic Event] topics:[fn_call, Bytes(8011bbf4cdf04e5bc6ac886935b99aa4b2c0cabde133f9d7fb3e656799f0a896), set_admin], data:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M
22: [Diagnostic Event] contract:CCABDO7UZXYE4W6GVSEGSNNZTKSLFQGKXXQTH6OX7M7GKZ4Z6CUJNGZN, topics:[fn_return, init_asset], data:Void
23: [Diagnostic Event] topics:[fn_call, Bytes(8011bbf4cdf04e5bc6ac886935b99aa4b2c0cabde133f9d7fb3e656799f0a896), init_asset], data:Bytes(0000000161616100000000000000000000000000000000000000000000000000000000000000000000000004)
Backtrace (newest first):
0: backtrace::backtrace::libunwind::trace
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.74/src/backtrace/libunwind.rs:116:5
backtrace::backtrace::trace_unsynchronized
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.74/src/backtrace/mod.rs:66:5
1: backtrace::backtrace::trace
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.74/src/backtrace/mod.rs:53:14
2: backtrace::capture::Backtrace::create
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.74/src/capture.rs:292:9
3: backtrace::capture::Backtrace::new_unresolved
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.74/src/capture.rs:287:9
4: soroban_env_host::host::error::<impl soroban_env_host::host::Host>::maybe_get_debug_info::{{closure}}
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host/error.rs:293:37
5: soroban_env_host::budget::Budget::with_shadow_mode
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/budget.rs:972:21
6: soroban_env_host::host::Host::with_debug_mode
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host.rs:615:24
7: soroban_env_host::host::error::<impl soroban_env_host::host::Host>::maybe_get_debug_info
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host/error.rs:290:13
8: soroban_env_host::host::error::<impl soroban_env_host::host::Host>::error::{{closure}}
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host/error.rs:274:23
9: soroban_env_host::budget::Budget::with_shadow_mode
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/budget.rs:972:21
10: soroban_env_host::host::Host::with_debug_mode
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host.rs:615:24
11: soroban_env_host::host::error::<impl soroban_env_host::host::Host>::error
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host/error.rs:261:9
12: <soroban_env_host::host::Host as soroban_env_common::env::EnvBase>::escalate_error_to_panic
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host.rs:767:26
13: soroban_sdk::env::internal::reject_err::{{closure}}
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-sdk-21.7.4/src/env.rs:52:23
14: core::result::Result<T,E>::map_err
at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/result.rs:854:27
15: soroban_sdk::env::internal::reject_err
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-sdk-21.7.4/src/env.rs:52:9
16: <soroban_sdk::env::Env as soroban_env_common::env::Env>::call
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-sdk-21.7.4/src/env.rs:1667:13
17: soroban_sdk::env::Env::invoke_contract
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-sdk-21.7.4/src/env.rs:379:18
18: versioning::VersioningClient::register
at /Users/tupui/Documents/Code/soroban-versioning/contracts/versioning/src/lib.rs:56:1
19: versioning::test::test
at /Users/tupui/Documents/Code/soroban-versioning/contracts/versioning/src/test.rs:62:14
20: versioning::test::test::{{closure}}
at /Users/tupui/Documents/Code/soroban-versioning/contracts/versioning/src/test.rs:12:10
21: core::ops::function::FnOnce::call_once
at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
thread 'test::test' panicked at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host.rs:768:9:
HostError: Error(Contract, #4)
Event log (newest first):
0: [Diagnostic Event] topics:[error, Error(Contract, #4)], data:"escalating error to panic"
1: [Diagnostic Event] topics:[error, Error(Contract, #4)], data:["contract call failed", register, [CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, "tansu", [CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5], "github.com/file.toml", "2ef4f49fdd8fa9dc463f1f06a094c26b88710990", CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V]]
2: [Failed Diagnostic Event (not emitted)] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, topics:[error, Error(Contract, #4)], data:"caught error from function"
3: [Failed Diagnostic Event (not emitted)] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, topics:[error, Error(Contract, #4)], data:"escalating error to panic"
4: [Failed Diagnostic Event (not emitted)] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, topics:[error, Error(Contract, #4)], data:["contract call failed", set_record, [Bytes(74616e7375), Bytes(786c), CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, 31536000]]
5: [Failed Diagnostic Event (not emitted)] contract:CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V, topics:[log], data:["VM call trapped with HostError", set_record, Error(Contract, #4)]
6: [Failed Diagnostic Event (not emitted)] contract:CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V, topics:[error, Error(Contract, #4)], data:"escalating error to VM trap from failed host function call: fail_with_error"
7: [Failed Diagnostic Event (not emitted)] contract:CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V, topics:[error, Error(Contract, #4)], data:["failing with contract error", 4]
8: [Failed Diagnostic Event (not emitted)] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, topics:[fn_call, Bytes(54ca65a58200bfffb708756d19fd134e1677063f85bb87e0c7a54abb480d375c), set_record], data:[Bytes(74616e7375), Bytes(786c), CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, 31536000]
9: [Failed Diagnostic Event (not emitted)] contract:CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V, topics:[fn_return, record], data:Void
10: [Failed Diagnostic Event (not emitted)] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, topics:[fn_call, Bytes(54ca65a58200bfffb708756d19fd134e1677063f85bb87e0c7a54abb480d375c), record], data:[Record, Bytes(2324dc49faf83ad010cee02118b8244566e3f9065e94a2694a8f57e377f7275c)]
11: [Diagnostic Event] topics:[fn_call, Bytes(0000000000000000000000000000000000000000000000000000000000000006), register], data:[CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, "tansu", [CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5], "github.com/file.toml", "2ef4f49fdd8fa9dc463f1f06a094c26b88710990", CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V]
12: [Diagnostic Event] contract:CCABDO7UZXYE4W6GVSEGSNNZTKSLFQGKXXQTH6OX7M7GKZ4Z6CUJNGZN, topics:[fn_return, mint], data:Void
13: [Contract Event] contract:CCABDO7UZXYE4W6GVSEGSNNZTKSLFQGKXXQTH6OX7M7GKZ4Z6CUJNGZN, topics:[mint, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M, CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, "aaa:GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJXFF"], data:10000000000000000
14: [Diagnostic Event] topics:[fn_call, Bytes(8011bbf4cdf04e5bc6ac886935b99aa4b2c0cabde133f9d7fb3e656799f0a896), mint], data:[CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM, 10000000000000000]
15: [Diagnostic Event] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4, topics:[fn_return, init], data:Void
16: [Diagnostic Event] topics:[fn_call, Bytes(0000000000000000000000000000000000000000000000000000000000000006), init], data:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM
17: [Diagnostic Event] contract:CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V, topics:[fn_return, init], data:Void
18: [Diagnostic Event] topics:[fn_call, Bytes(54ca65a58200bfffb708756d19fd134e1677063f85bb87e0c7a54abb480d375c), init], data:[CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4, 100, CCABDO7UZXYE4W6GVSEGSNNZTKSLFQGKXXQTH6OX7M7GKZ4Z6CUJNGZN, 31536000, [Bytes(786c6d), Bytes(7374656c6c6172), Bytes(77616c6c6574), Bytes(64616f)]]
19: [Diagnostic Event] contract:CCABDO7UZXYE4W6GVSEGSNNZTKSLFQGKXXQTH6OX7M7GKZ4Z6CUJNGZN, topics:[fn_return, set_admin], data:Void
20: [Contract Event] contract:CCABDO7UZXYE4W6GVSEGSNNZTKSLFQGKXXQTH6OX7M7GKZ4Z6CUJNGZN, topics:[set_admin, GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJXFF, "aaa:GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJXFF"], data:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M
21: [Diagnostic Event] topics:[fn_call, Bytes(8011bbf4cdf04e5bc6ac886935b99aa4b2c0cabde133f9d7fb3e656799f0a896), set_admin], data:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M
22: [Diagnostic Event] contract:CCABDO7UZXYE4W6GVSEGSNNZTKSLFQGKXXQTH6OX7M7GKZ4Z6CUJNGZN, topics:[fn_return, init_asset], data:Void
23: [Diagnostic Event] topics:[fn_call, Bytes(8011bbf4cdf04e5bc6ac886935b99aa4b2c0cabde133f9d7fb3e656799f0a896), init_asset], data:Bytes(0000000161616100000000000000000000000000000000000000000000000000000000000000000000000004)
Backtrace (newest first):
0: backtrace::backtrace::libunwind::trace
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.74/src/backtrace/libunwind.rs:116:5
backtrace::backtrace::trace_unsynchronized
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.74/src/backtrace/mod.rs:66:5
1: backtrace::backtrace::trace
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.74/src/backtrace/mod.rs:53:14
2: backtrace::capture::Backtrace::create
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.74/src/capture.rs:292:9
3: backtrace::capture::Backtrace::new_unresolved
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.74/src/capture.rs:287:9
4: soroban_env_host::host::error::<impl soroban_env_host::host::Host>::maybe_get_debug_info::{{closure}}
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host/error.rs:293:37
5: soroban_env_host::budget::Budget::with_shadow_mode
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/budget.rs:972:21
6: soroban_env_host::host::Host::with_debug_mode
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host.rs:615:24
7: soroban_env_host::host::error::<impl soroban_env_host::host::Host>::maybe_get_debug_info
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host/error.rs:290:13
8: soroban_env_host::host::error::<impl soroban_env_host::host::Host>::error::{{closure}}
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host/error.rs:274:23
9: soroban_env_host::budget::Budget::with_shadow_mode
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/budget.rs:972:21
10: soroban_env_host::host::Host::with_debug_mode
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host.rs:615:24
11: soroban_env_host::host::error::<impl soroban_env_host::host::Host>::error
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host/error.rs:261:9
12: <soroban_env_host::host::Host as soroban_env_common::env::EnvBase>::escalate_error_to_panic
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host.rs:767:26
13: soroban_sdk::env::internal::reject_err::{{closure}}
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-sdk-21.7.4/src/env.rs:52:23
14: core::result::Result<T,E>::map_err
at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/result.rs:854:27
15: soroban_sdk::env::internal::reject_err
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-sdk-21.7.4/src/env.rs:52:9
16: <soroban_sdk::env::Env as soroban_env_common::env::Env>::call
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-sdk-21.7.4/src/env.rs:1667:13
17: soroban_sdk::env::Env::invoke_contract
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-sdk-21.7.4/src/env.rs:379:18
18: versioning::VersioningClient::register
at /Users/tupui/Documents/Code/soroban-versioning/contracts/versioning/src/lib.rs:56:1
19: versioning::test::test
at /Users/tupui/Documents/Code/soroban-versioning/contracts/versioning/src/test.rs:62:14
20: versioning::test::test::{{closure}}
at /Users/tupui/Documents/Code/soroban-versioning/contracts/versioning/src/test.rs:12:10
21: core::ops::function::FnOnce::call_once
at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
stack backtrace:
0: rust_begin_unwind
at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5
1: core::panicking::panic_fmt
at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:74:14
2: <soroban_env_host::host::Host as soroban_env_common::env::EnvBase>::escalate_error_to_panic
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-env-host-21.2.1/src/host.rs:768:9
3: soroban_sdk::env::internal::reject_err::{{closure}}
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-sdk-21.7.4/src/env.rs:52:23
4: core::result::Result<T,E>::map_err
at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/result.rs:854:27
5: soroban_sdk::env::internal::reject_err
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-sdk-21.7.4/src/env.rs:52:9
6: <soroban_sdk::env::Env as soroban_env_common::env::Env>::call
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-sdk-21.7.4/src/env.rs:1667:13
7: soroban_sdk::env::Env::invoke_contract
at /Users/tupui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/soroban-sdk-21.7.4/src/env.rs:379:18
8: versioning::VersioningClient::register
at ./src/lib.rs:56:1
9: versioning::test::test
at ./src/test.rs:62:14
10: versioning::test::test::{{closure}}
at ./src/test.rs:12:10
11: core::ops::function::FnOnce::call_once
at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
12: core::ops::function::FnOnce::call_once
at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Writing test snapshot file for test "test::test" to "test_snapshots/test/test.1.json".
Writing test snapshot file for test "test::test_utils" to "test_snapshots/test/test_utils.1.json".
error: test failed, to rerun pass `--lib`
error: 1 target failed:
`--lib`
Process finished with exit code 101 There are a few things here. First the stacktrace is too long 😅 It's showing me too much of what happened with previous calls I made running the test suite. It took me a while, too long I care to admit, to actually understand that and it was not relevant to my issue. Removing all that, we are left with 10 items, still a bit too long and there is quite some repetition due to this escalation in the stack. What you might eventually start to notice is the repetition of https://github.com/Creit-Tech/sorobandomains-sc/blob/main/contracts/registry/src/errors.rs And here we have it in the enum: I am not sure how all that is possible, but if there was a way to resurface better the meaning of error codes, that would be really helpful. Then, adding colors as @kalepail suggest could be super helpful to separate sections. This could also be accomplished by splitting a bit more the output of the trace. I guess in some cases you want this super verbose output and my case is "too simple". But that's the thing to me simple cases like these should be simple to debug and for now it's hard. Hope that helps 😃 |
@tupui Thank you for sharing more details and an example, this is helpful as we think about how to restructure this data.
Fyi if you have the .wasm for the contract, or you know it's address on chain, you can lookup the error using the specification without the source.
@Ifropc Maybe we should add another sub-command to |
Thanks, I did not know that command 👍 That will help in such cases. Might be more tricky if the underlying contract does not properly validate inputs and would break (I did not check, so just talking hypothetically here.) |
I am not sure if this is the right place, but I found another interesting case with some obscure error message. If you are using storage, at compile time it does not tell you if you are using the correct type to store and update values. e.g. with this structure #[contracttype]
pub struct Proposal {
...
}
#[contracttype]
pub struct Dao {
pub proposals: Vec<Proposal>,
}
#[contracttype]
pub enum ProjectKey {
...
DaoTotalProposals(Bytes),
} I was wrongly updating an entry of env.storage()
.persistent()
.set(&ProjectKey::Dao(project_key, page), &proposal) And this gives this error
(Additionally it was also not pointing directly to the problematic line but I could find that using RustRover's debugger.) This bugged me for a while. Here I got some luck with Stella 😅
Stella's full responseUnderstanding the Storage Get ErrorThis specific error occurs when trying to retrieve data from storage where there's a mismatch between the data structure you're trying to deserialize into and the actual data stored. Common Causes
// If you stored data as one type
#[derive(Clone)]
#[contracttype]
pub struct OldDao {
field1: String,
field2: i32,
}
// But trying to retrieve as another type
#[derive(Clone)]
#[contracttype]
pub struct NewDao {
field1: String,
field2: i32,
field3: Vec<String>, // Added field
} How to Fix
#[derive(Clone)]
#[contracttype]
pub struct Dao {
// Make sure this matches exactly what was stored
// Including all fields and their types
}
// When retrieving
let dao: Dao = env.storage().persistent()
.get(&DataKey::Dao(project_key, page))
.unwrap_or_else(|| panic!("Not found"));
// Safe retrieval with error handling
if let Some(dao) = env.storage().persistent().get(&DataKey::Dao(project_key, page)) {
// Data exists and matches the type
} else {
// Handle case where data doesn't exist
} Best Practices
If the error persists, try:
Sources: |
I can see how that error message didn't point at the issue at all. This is, in general, the issue with errors within host functions, they have no context where they're being used and for what. So in this case that host function was being used for custom type struct unpacking. The context about that is in the sdk, but the error is being raised and the contract is being terminated before returning back to the contract where the context is. That's cool to see Stella bot could recognise the issue. |
I think we should improve the readability of the diagnostic event and stack trace outputs that the environment generates on the console and in tests when there are failures.
This is not about improving the contents / data within the diagnostic events, and only the presentation of the existing data, so it is easier to glance and digest.
An example of the existing output as of
v21.2.1
:The text was updated successfully, but these errors were encountered: