Skip to content

Commit 6c261a0

Browse files
authored
Change backtrace warning (#3656)
Closes #3272 commit-id:0744f312
1 parent be1890a commit 6c261a0

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

crates/forge/src/profile_validation/backtrace.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fn check_scarb_version(scarb_metadata: &Metadata) -> anyhow::Result<()> {
2323

2424
/// Checks if the runtime profile settings in the provided from [`Metadata`] contain the required entries for backtrace generation.
2525
fn check_profile(scarb_metadata: &Metadata) -> anyhow::Result<()> {
26+
// TODO(#3679): Add `panic-backtrace = true` entry when we decide to bump minimal scarb version to 2.12.
2627
const BACKTRACE_REQUIRED_ENTRIES: &[(&str, &str)] = &[
2728
("unstable-add-statements-functions-debug-info", "true"),
2829
("unstable-add-statements-code-locations-debug-info", "true"),

crates/forge/src/warn.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use forge_runner::backtrace::is_backtrace_enabled;
44
use forge_runner::package_tests::with_config_resolved::TestTargetWithResolvedConfig;
55
use foundry_ui::UI;
66
use foundry_ui::components::warning::WarningMessage;
7+
use indoc::formatdoc;
78
use scarb_api::{ScarbCommand, package_matches_version_requirement};
89
use scarb_metadata::Metadata;
910
use semver::{Comparator, Op, Version, VersionReq};
@@ -184,7 +185,7 @@ pub fn warn_if_snforge_std_does_not_match_package_version(
184185
Ok(())
185186
}
186187

187-
// TODO(#3272)
188+
// TODO(#3679): Remove this function when we decide to bump minimal scarb version to 2.12.
188189
pub(crate) fn warn_if_backtrace_without_panic_hint(scarb_metadata: &Metadata, ui: &UI) {
189190
if is_backtrace_enabled() {
190191
let is_panic_backtrace_set = scarb_metadata
@@ -202,10 +203,18 @@ pub(crate) fn warn_if_backtrace_without_panic_hint(scarb_metadata: &Metadata, ui
202203
});
203204

204205
if !is_panic_backtrace_set {
205-
ui.println(
206-
&WarningMessage::new("To get accurate backtrace results, it is required to use the configuration available in the latest Cairo version. \
207-
For more details, please visit https://foundry-rs.github.io/starknet-foundry/snforge-advanced-features/backtrace.html"
208-
));
206+
let message = formatdoc! {
207+
"Scarb version should be 2.12 or higher and `Scarb.toml` should have the following Cairo compiler configuration to get accurate backtrace results:
208+
209+
[profile.{profile}.cairo]
210+
unstable-add-statements-functions-debug-info = true
211+
unstable-add-statements-code-locations-debug-info = true
212+
panic-backtrace = true # only for scarb 2.12 or higher
213+
... other entries ...
214+
",
215+
profile = scarb_metadata.current_profile
216+
};
217+
ui.println(&WarningMessage::new(message));
209218
}
210219
}
211220
}

crates/forge/tests/e2e/backtrace.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ fn test_backtrace() {
3636
output,
3737
indoc! {
3838
"
39-
[WARNING] To get accurate backtrace results, it is required to use the configuration available in the latest Cairo version. For more details, please visit https://foundry-rs.github.io/starknet-foundry/snforge-advanced-features/backtrace.html
39+
[WARNING] Scarb version should be 2.12 or higher and `Scarb.toml` should have the following Cairo compiler configuration to get accurate backtrace results:
40+
41+
[profile.dev.cairo]
42+
unstable-add-statements-functions-debug-info = true
43+
unstable-add-statements-code-locations-debug-info = true
44+
panic-backtrace = true # only for scarb 2.12 or higher
45+
... other entries ...
46+
4047
[FAIL] backtrace_vm_error::Test::test_unwrapped_call_contract_syscall
4148
4249
Failure data:

0 commit comments

Comments
 (0)