Skip to content

ref(errors): Use enum for stacktrace order #96719

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

Merged
merged 4 commits into from
Jul 30, 2025

Conversation

lobsterkatie
Copy link
Member

@lobsterkatie lobsterkatie commented Jul 29, 2025

Users can choose to display their stacktraces on the issue details page in reverse order, using the stacktrace_order user option. With a few caveats (see below), under the hood we store the option values as the strings "-1" (default), "1" (chronological order, with newest frame last), and "2" (same as default, reverse chronological order, with newest frame first).* In the front end we use numbers instead of strings, but with corresponding values.

Because the mapping is not obvious, this adds to the backend a StacktraceOrder enum (and a _SerializedStacktraceOrder enum to handle the conversion to numbers), and uses them rather than the corresponding strings/numbers. A similar change for the front end will happen in a follow-up PR.

Note: The description above is not strictly correct, for two reasons (each of which now has a corresponding TODO):

  1. There are a small number of users which don't have any of these and instead have the empty string as their option value. This is treated the same as not having the option set at all, so it's not breaking anything, but we should nonetheless probably just clean those up.
  2. "2" is not always the same as the default, or rather, the default behavior is not always to have the newest frame first. There is one place, (indirectly) in the Stacktrace interface's to_string method, where for Python events (and events with no platform, though practically speaking Relay normalization means there's always a platform) the default is the opposite, newest last. This doesn't match stacktrace ordering behavior anywhere else, so it might be worth investigating if we want to keep that special-casing in place. (It's also not immediately obvious where we (ultimately) use that method. Back when the special-casing was introduced (in late 2012), it was controlling the result of Stacktrace.to_html, but now we obviously let react create the HTML, and in our current front end there's no such exception for Python.)

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 29, 2025
@lobsterkatie lobsterkatie force-pushed the kmclb-use-enum-for-stacktrace-order-in-backend branch from 3f86b01 to 84ddde9 Compare July 29, 2025 23:33
@lobsterkatie lobsterkatie force-pushed the kmclb-use-enum-for-stacktrace-order-in-backend branch from 84ddde9 to bb4db8b Compare July 29, 2025 23:37
@lobsterkatie lobsterkatie force-pushed the kmclb-use-enum-for-stacktrace-order-in-backend branch from bb4db8b to 2753412 Compare July 30, 2025 00:31
@lobsterkatie lobsterkatie marked this pull request as ready for review July 30, 2025 00:51
@lobsterkatie lobsterkatie requested a review from a team as a code owner July 30, 2025 00:51
@@ -86,16 +93,19 @@ def get_context(lineno, context_line, pre_context=None, post_context=None):


def is_newest_frame_first(event):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this function could return a StacktraceOrder directly, there's no need to turn the enum into a boolean. Similarly, the newest_first parameter of get_stacktrace could then be a StacktraceOrder.

Copy link
Member Author

@lobsterkatie lobsterkatie Jul 30, 2025

Choose a reason for hiding this comment

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

I think those are both valid points, but my preference would be to address them in a follow-up PR, so that this one can remain solely about switching to using the enum. (Happy to add a TODO about it here, though, since it would make sense to address your points alongside addressing the Python-special-casing question.)

lobsterkatie added a commit that referenced this pull request Jul 30, 2025
This is a follow-up to #96719, which added a backend `StacktraceOrder` enum, doing the same in the front end. It also clarifies the labels for the `Newest` (now `Newest first`) and `Oldest` (now `Oldest first`) options in user preferences.
@lobsterkatie lobsterkatie force-pushed the kmclb-use-enum-for-stacktrace-order-in-backend branch from 2753412 to 66dadb4 Compare July 30, 2025 19:31
@lobsterkatie lobsterkatie merged commit c0420fb into master Jul 30, 2025
64 checks passed
@lobsterkatie lobsterkatie deleted the kmclb-use-enum-for-stacktrace-order-in-backend branch July 30, 2025 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants