TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Stack Traces Are Underrated

96 点作者 zoidb2 个月前

20 条评论

bob10292 个月前
Stack traces are your #1 ally when supporting someone else&#x27;s legacy production pile.<p>Once you get comfortable with how they work and what information they contain, you can hit the ground running anywhere. Stack traces will teach you about the product architecture faster than anyone on the team can.<p>As you embrace them, you take the little bit of extra time to make sure they go well. For example, re-throwing exceptions correctly, properly awaiting results, etc. Very minor details that make all the difference.<p>A broader outcome of this enlightenment is preference for monolithic products. Stack traces fare poorly across web service and API boundaries. If you&#x27;ve only ever worked with microservice architectures, the notion of a stack trace may seem distracting.
评论 #43319081 未加载
the_mitsuhiko2 个月前
&gt; But Rust has a better workaround to create stack traces: the backtrace module, which allows capturing stack traces that you can then add to the errors you return. The main problem with this approach is that you still have to add the stack trace to each error and also trust library authors to do so.<p>That&#x27;s technically true, but the situation is not as dire. Many errors do not need stack traces. That so few carry a backtrace in Rust is mostly a result of the functionality still not being stable [1].<p>The I think bigger issue is that people largely have given up on stack traces I think, in parts because of async programming. There are more and more programming patterns and libraries where back traces are completely useless. For instance in JavaScript I keep working with dependencies that just come minified or transpiled straight out of npm. In theory node has async stack traces now, but I have yet to see this work through `setTimeout` and friends. It&#x27;s very common to lose parts of the stack.<p>Because there are now so many situations where stack traces are unreliable, more and more programmers seemingly do lose trust in them and don&#x27;t see the value they once provided.<p>I also see it in parts at Sentry where a shocking number of customers are completely willing to work with just minified stack traces and not set up source maps to make them readable.<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;issues&#x2F;99301" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;issues&#x2F;99301</a>
评论 #43318520 未加载
评论 #43319273 未加载
评论 #43319050 未加载
评论 #43321915 未加载
评论 #43318526 未加载
CMDBob2 个月前
A stack trace (or even better, a minidump with the call stack!) is one of the most useful debugging things for me. Hell, the call stack in general is super useful to me!<p>I can look at a stack trace, go &quot;oh, function X is misbehaving after being called by function Y, from function Z&quot;, and work out what&#x27;s gone wrong from the context clues, and other debugger info. As a game developer, with codebases that are big, semi-monolithic codebases, it&#x27;s essential, especially when code crosses the gameplay&#x2F;engine and engine&#x2F;kernel barriers.
montebicyclelo2 个月前
Great point. I&#x27;ve found it&#x27;s very often possible to understand and fix problems &quot;one shot&quot; from stack traces alone — and we&#x27;re talking production builds here... So I wouldn&#x27;t turn them off, (an idea mentioned in the article), unless profiling shows that they are one of the last things preventing the code from reaching the target performance.
windward2 个月前
&gt;Are they just not used to having them so that they don&#x27;t miss them?<p>The languages that I work in that don&#x27;t print useful traces are typically strongishly-typed system languages. So I miss them - sometimes having to step through offending lines of code in a debugger - but I also completely avoid a whole class of bugs that are responsible for most of my stack traces in Python.<p>TFA&#x27;s example isn&#x27;t one of these, but is a function that would have a return code checked and logged if erroneous. This class of bug also can&#x27;t be inlined and makes an easy breakpoint-ee.
TinkersW2 个月前
They are useful sure, and I print a stacktrace on any type of error&#x2F;exception, but often breaking into the debugger is even more useful and faster as you can see local variables, program state, and what other threads happen to be doing.
评论 #43318387 未加载
anonzzzies2 个月前
I am a big fan of Lisp SBCL stack traces; even in complex projects I never saw before, I&#x27;m almost always able to read, interpret and fix the issue just from that.
评论 #43323041 未加载
zokier2 个月前
Kinda related, but I feel it would be useful for log entries to include file&#x2F;lineno and&#x2F;or some unique identifier. Helps both pinpointing where some weird message comes from, and for searching for specific entries in the logs.<p>Sure, you can grep the log message but it can be difficult if it has some templating&#x2F;formatting going on, and it can be pretty easy to end up with non-unique messages.
评论 #43319021 未加载
GuB-422 个月前
I don&#x27;t know if it is part of the reason but stack traces can be considered a vulnerability in some situations.<p>Also, for &quot;normal&quot; errors, you shouldn&#x27;t need a stack trace. For example, &quot;file not found&quot; is, from the point of view of the developer an expected situation and should be handled with the same amount of care as it the file was present. You don&#x27;t dump the internals to the user when you have successfully opened the file, so don&#x27;t dump them when you haven&#x27;t.<p>For unexpected errors (i.e. bugs), the crash, abort, panic, or whatever it is called in your language. These will usually give you a stack trace, or a core dump from where you can extract the stack trace and more.<p>What I would wish for however would be a standard feature in languages to display a stack trace on command. Many languages have it, but even when they do, they could be more prominent. This way, if you encounter an unexpected situation you want to debug without crashing and without a debugger attached, you can call it.
albertzeyer2 个月前
Stack traces are very valuable. Sometimes it can even help to attach them to some object creation, when you later wonder why&#x2F;how&#x2F;where this object was created. E.g. in TensorFlow, every single Tensor had a traceback attached to it, so when there was any error later on, it would show you where it was created. This is maybe less needed now with eager mode, but you might have other similar situations.<p>One problem with stack traces is maybe that they can be too verbose. E.g. if you print them for any warning you print to log (or stdout). Sometimes they will be extremely helpful for debugging some problem, but in many cases, you maybe don&#x27;t need them (you know why you get the warning and&#x2F;or you don&#x27;t care about it).<p>You could also add more information to the stack trace such as local variables. That can be even more helpful for debugging then, but again adds more verbosity.<p>For example, we often use this to add information about relevant local variables: <a href="https:&#x2F;&#x2F;github.com&#x2F;albertz&#x2F;py_better_exchook" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;albertz&#x2F;py_better_exchook</a><p>One solution to the problem with verbosity is when you have foldable text output. Then the stack trace is folded away (not shown in all details) and you can unfold it to see the details. See the DomTerm demo here: <a href="https:&#x2F;&#x2F;github.com&#x2F;albertz&#x2F;py_better_exchook#domterm" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;albertz&#x2F;py_better_exchook#domterm</a><p>Some more on text folding:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;PerBothner&#x2F;DomTerm&#x2F;issues&#x2F;54" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;PerBothner&#x2F;DomTerm&#x2F;issues&#x2F;54</a><p><a href="https:&#x2F;&#x2F;gitlab.com&#x2F;gnachman&#x2F;iterm2&#x2F;-&#x2F;issues&#x2F;4950" rel="nofollow">https:&#x2F;&#x2F;gitlab.com&#x2F;gnachman&#x2F;iterm2&#x2F;-&#x2F;issues&#x2F;4950</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;xtermjs&#x2F;xterm.js&#x2F;issues&#x2F;1875" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;xtermjs&#x2F;xterm.js&#x2F;issues&#x2F;1875</a><p><a href="https:&#x2F;&#x2F;gitlab.freedesktop.org&#x2F;terminal-wg&#x2F;specifications&#x2F;-&#x2F;issues&#x2F;3" rel="nofollow">https:&#x2F;&#x2F;gitlab.freedesktop.org&#x2F;terminal-wg&#x2F;specifications&#x2F;-&#x2F;...</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;vercel&#x2F;hyper&#x2F;issues&#x2F;1093" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;vercel&#x2F;hyper&#x2F;issues&#x2F;1093</a>
harperlee2 个月前
My main problem with (jvm) stack traces is that they generally don&#x27;t include information about the values that are passed to the function calls, so you get the structure of the code, but not the actual value that could help you reproduce the error. I know that once you deal with relatively complex objects that are not trivially serializable you get an address, which is not super useful, but in some codebases &#x2F; problem areas you still could be getting a lot of information that gets lost due to that design decision.
Chilinot2 个月前
I have been an avid proponent of the way errors are managed in Rust and Go for a long time. However, this article raises a very good point. Before i started developing in Rust and Go, i did Java and python for several years. And damn, do i miss those stacktraces every now and then when something bad happens that isn&#x27;t properly handled by the code.<p>Still, i do think returning the error as a return value is better than having a completely separate flow when dealing with exceptions. I like that it forces me to properly deal with an error and not just ignore it and think something like &quot;meh, i&#x27;ll get to this later&quot;. Because i will never &quot;get to it later&quot;.
评论 #43318908 未加载
cm21872 个月前
In C# the quasi mandatory async&#x2F;await for everything has many downsides, particularly for debugging. It breaks all stack traces. It also makes it impossible to pause the code.
评论 #43318479 未加载
fedeb952 个月前
hiding stack traces is a bad practice and should be avoided unless you&#x27;re in the last layer of the application (i.e. presentation to the user).
creshal2 个月前
Stack traces are underrated, unless you&#x27;re developing EnterpriseJavaSingletonFactoryAbstractionFactoryFactories, in which case they&#x27;re buffer overflows on your poor log analyzer
someothherguyy2 个月前
Stupid clickbait headline for a famished article
berkes2 个月前
Way before I consistently used step debuggers and would just &quot;print-debug&quot; println(&quot;why are you here?&quot;) or &quot;raise-debug&quot; raise new Error(&quot;huh?&quot;), I tinkered with a step debugger, but found it too complex and hard. But I remember that it also allowed me to move backwards in the stack.<p>It allowed me to go some frames back - lines up, up in the stack. I don&#x27;t recall the name of this debugger, nor what language it was. But I&#x27;ve never since seen this, yet very often wished I had it (for rust, javascript, python, mostly).<p>Did I misremember? Can such a thing exist? Does it exist?
评论 #43318206 未加载
评论 #43318396 未加载
cyberax2 个月前
Don&#x27;t worry. Just wait until you start doing async stuff, especially with React.<p>You&#x27;ll be dreaming of good old times of linear stacktraces.
评论 #43318595 未加载
评论 #43318212 未加载
rollulus2 个月前
Depends on the audience. As a user I&#x27;d rather see &quot;can&#x27;t load data: failed to parse header: wrong number of elements&quot; than a stack trace with WrongNumbersOfElementsException at the tail.
评论 #43318588 未加载
logicallee2 个月前
While you&#x27;re debugging using AI (specifically, ChatGPT o1), you can benefit from copying stack traces. It debugs better than if you just describe what&#x27;s wrong.<p>Another tip: I have found that it is helpful to ask AI to &quot;deeply analyze&quot; (use those words) and think about the problem without providing a solution (say &quot;don&#x27;t reply with any code&quot;). If you don&#x27;t do that, it will take its first guess and then eagerly start outputing code that is still wrong and doesn&#x27;t really identify or fix the issue. When you ask it to deeply analyze what&#x27;s wrong and not reply with any code, it frequently finds the true underling problem, and then you can ask for how to solve it in the next step.