mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-29 03:00:45 -04:00
241 lines
18 KiB
HTML
241 lines
18 KiB
HTML
<!DOCTYPE html>
|
|
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Stack trace manipulation functions — stacktrace • shiny</title><!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png"><link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png"><link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png"><link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png"><link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png"><link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png"><!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous"><script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css"><script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet"><script src="../pkgdown.js"></script><meta property="og:title" content="Stack trace manipulation functions — stacktrace"><meta property="og:description" content="Advanced (borderline internal) functions for capturing, printing, and
|
|
manipulating stack traces."><meta property="og:image" content="/logo.png"><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
|
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
|
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
|
<![endif]--></head><body data-spy="scroll" data-target="#toc">
|
|
|
|
|
|
<div class="container template-reference-topic">
|
|
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
|
|
<div class="container">
|
|
<div class="navbar-header">
|
|
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
|
|
<span class="sr-only">Toggle navigation</span>
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
</button>
|
|
<span class="navbar-brand">
|
|
<a class="navbar-link" href="../index.html">shiny</a>
|
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="">1.7.1.9003</span>
|
|
</span>
|
|
</div>
|
|
|
|
<div id="navbar" class="navbar-collapse collapse">
|
|
<ul class="nav navbar-nav"><li>
|
|
<a href="../reference/index.html">Reference</a>
|
|
</li>
|
|
<li>
|
|
<a href="../news/index.html">Changelog</a>
|
|
</li>
|
|
</ul><ul class="nav navbar-nav navbar-right"><li>
|
|
<a href="https://github.com/rstudio/shiny/" class="external-link">
|
|
<span class="fab fa-github fa-lg"></span>
|
|
|
|
</a>
|
|
</li>
|
|
</ul></div><!--/.nav-collapse -->
|
|
</div><!--/.container -->
|
|
</div><!--/.navbar -->
|
|
|
|
|
|
|
|
</header><div class="row">
|
|
<div class="col-md-9 contents">
|
|
<div class="page-header">
|
|
<h1>Stack trace manipulation functions</h1>
|
|
<small class="dont-index">Source: <a href="https://github.com/rstudio/shiny/blob/HEAD/R/conditions.R" class="external-link"><code>R/conditions.R</code></a></small>
|
|
<div class="hidden name"><code>stacktrace.Rd</code></div>
|
|
</div>
|
|
|
|
<div class="ref-description">
|
|
<p>Advanced (borderline internal) functions for capturing, printing, and
|
|
manipulating stack traces.</p>
|
|
</div>
|
|
|
|
<div id="ref-usage">
|
|
<div class="sourceCode"><pre class="sourceCode r"><code><span class="fu">captureStackTraces</span><span class="op">(</span><span class="va">expr</span><span class="op">)</span>
|
|
|
|
<span class="fu">withLogErrors</span><span class="op">(</span>
|
|
<span class="va">expr</span>,
|
|
full <span class="op">=</span> <span class="fu"><a href="devmode.html">get_devmode_option</a></span><span class="op">(</span><span class="st">"shiny.fullstacktrace"</span>, <span class="cn">FALSE</span><span class="op">)</span>,
|
|
offset <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/options.html" class="external-link">getOption</a></span><span class="op">(</span><span class="st">"shiny.stacktraceoffset"</span>, <span class="cn">TRUE</span><span class="op">)</span>
|
|
<span class="op">)</span>
|
|
|
|
<span class="fu">printError</span><span class="op">(</span>
|
|
<span class="va">cond</span>,
|
|
full <span class="op">=</span> <span class="fu"><a href="devmode.html">get_devmode_option</a></span><span class="op">(</span><span class="st">"shiny.fullstacktrace"</span>, <span class="cn">FALSE</span><span class="op">)</span>,
|
|
offset <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/options.html" class="external-link">getOption</a></span><span class="op">(</span><span class="st">"shiny.stacktraceoffset"</span>, <span class="cn">TRUE</span><span class="op">)</span>
|
|
<span class="op">)</span>
|
|
|
|
<span class="fu">printStackTrace</span><span class="op">(</span>
|
|
<span class="va">cond</span>,
|
|
full <span class="op">=</span> <span class="fu"><a href="devmode.html">get_devmode_option</a></span><span class="op">(</span><span class="st">"shiny.fullstacktrace"</span>, <span class="cn">FALSE</span><span class="op">)</span>,
|
|
offset <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/options.html" class="external-link">getOption</a></span><span class="op">(</span><span class="st">"shiny.stacktraceoffset"</span>, <span class="cn">TRUE</span><span class="op">)</span>
|
|
<span class="op">)</span>
|
|
|
|
<span class="fu">conditionStackTrace</span><span class="op">(</span><span class="va">cond</span><span class="op">)</span>
|
|
|
|
<span class="fu">conditionStackTrace</span><span class="op">(</span><span class="va">cond</span><span class="op">)</span> <span class="op"><-</span> <span class="va">value</span>
|
|
|
|
<span class="fu">..stacktraceon..</span><span class="op">(</span><span class="va">expr</span><span class="op">)</span>
|
|
|
|
<span class="fu">..stacktraceoff..</span><span class="op">(</span><span class="va">expr</span><span class="op">)</span></code></pre></div>
|
|
</div>
|
|
|
|
<div id="arguments">
|
|
<h2>Arguments</h2>
|
|
<dl><dt>expr</dt>
|
|
<dd><p>The expression to wrap.</p></dd>
|
|
|
|
|
|
<dt>full</dt>
|
|
<dd><p>If <code>TRUE</code>, then every element of <code><a href="https://rdrr.io/r/base/sys.parent.html" class="external-link">sys.calls()</a></code> will be
|
|
included in the stack trace. By default (<code>FALSE</code>), calls that Shiny
|
|
deems uninteresting will be hidden.</p></dd>
|
|
|
|
|
|
<dt>offset</dt>
|
|
<dd><p>If <code>TRUE</code> (the default), srcrefs will be reassigned from
|
|
the calls they originated from, to the destinations of those calls. If
|
|
you're used to stack traces from other languages, this feels more
|
|
intuitive, as the definition of the function indicated in the call and the
|
|
location specified by the srcref match up. If <code>FALSE</code>, srcrefs will be
|
|
left alone (traditional R treatment where the srcref is of the callsite).</p></dd>
|
|
|
|
|
|
<dt>cond</dt>
|
|
<dd><p>A condition that may have previously been annotated by
|
|
<code>captureStackTraces</code> (or <code>withLogErrors</code>).</p></dd>
|
|
|
|
|
|
<dt>value</dt>
|
|
<dd><p>The stack trace value to assign to the condition.</p></dd>
|
|
|
|
</dl></div>
|
|
<div id="value">
|
|
<h2>Value</h2>
|
|
|
|
|
|
<p><code>printError</code> and <code>printStackTrace</code> return
|
|
<code><a href="https://rdrr.io/r/base/invisible.html" class="external-link">invisible()</a></code>. The other functions pass through the results of
|
|
<code>expr</code>.</p>
|
|
</div>
|
|
<div id="details">
|
|
<h2>Details</h2>
|
|
<p><code>captureStackTraces</code> runs the given <code>expr</code> and if any
|
|
<em>uncaught</em> errors occur, annotates them with stack trace info for use
|
|
by <code>printError</code> and <code>printStackTrace</code>. It is not necessary to use
|
|
<code>captureStackTraces</code> around the same expression as
|
|
<code>withLogErrors</code>, as the latter includes a call to the former. Note
|
|
that if <code>expr</code> contains calls (either directly or indirectly) to
|
|
<code>try</code>, or <code>tryCatch</code> with an error handler, stack traces therein
|
|
cannot be captured unless another <code>captureStackTraces</code> call is
|
|
inserted in the interior of the <code>try</code> or <code>tryCatch</code>. This is
|
|
because these calls catch the error and prevent it from traveling up to the
|
|
condition handler installed by <code>captureStackTraces</code>.</p>
|
|
<p><code>withLogErrors</code> captures stack traces and logs errors that
|
|
occur in <code>expr</code>, but does allow errors to propagate beyond this point
|
|
(i.e. it doesn't catch the error). The same caveats that apply to
|
|
<code>captureStackTraces</code> with regard to <code>try</code>/<code>tryCatch</code> apply
|
|
to <code>withLogErrors</code>.</p>
|
|
<p><code>printError</code> prints the error and stack trace (if any) using
|
|
<code>warning(immediate.=TRUE)</code>. <code>printStackTrace</code> prints the stack
|
|
trace only.</p>
|
|
<p><code>conditionStackTrace</code> and <code>conditionStackTrace<-</code> are
|
|
accessor functions for getting/setting stack traces on conditions.</p>
|
|
<p>The two functions <code>..stacktraceon..</code> and
|
|
<code>..stacktraceoff..</code> have no runtime behavior during normal execution;
|
|
they exist only to create artifacts on the stack trace (sys.call()) that
|
|
instruct the stack trace pretty printer what parts of the stack trace are
|
|
interesting or not. The initial state is 1 and we walk from the outermost
|
|
call inwards. Each ..stacktraceoff.. decrements the state by one, and each
|
|
..stacktraceon.. increments the state by one. Any stack trace frame whose
|
|
value is less than 1 is hidden, and finally, the ..stacktraceon.. and
|
|
..stacktraceoff.. calls themselves are hidden too.</p>
|
|
</div>
|
|
|
|
<div id="ref-examples">
|
|
<h2>Examples</h2>
|
|
<div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span class="co"># Keeps tryCatch and withVisible related calls off the</span></span>
|
|
<span class="r-in"><span class="co"># pretty-printed stack trace</span></span>
|
|
<span class="r-in"></span>
|
|
<span class="r-in"><span class="va">visibleFunction1</span> <span class="op"><-</span> <span class="kw">function</span><span class="op">(</span><span class="op">)</span> <span class="op">{</span></span>
|
|
<span class="r-in"> <span class="kw"><a href="https://rdrr.io/r/base/stop.html" class="external-link">stop</a></span><span class="op">(</span><span class="st">"Kaboom!"</span><span class="op">)</span></span>
|
|
<span class="r-in"><span class="op">}</span></span>
|
|
<span class="r-in"></span>
|
|
<span class="r-in"><span class="va">visibleFunction2</span> <span class="op"><-</span> <span class="kw">function</span><span class="op">(</span><span class="op">)</span> <span class="op">{</span></span>
|
|
<span class="r-in"> <span class="fu">visibleFunction1</span><span class="op">(</span><span class="op">)</span></span>
|
|
<span class="r-in"><span class="op">}</span></span>
|
|
<span class="r-in"></span>
|
|
<span class="r-in"><span class="va">hiddenFunction</span> <span class="op"><-</span> <span class="kw">function</span><span class="op">(</span><span class="va">expr</span><span class="op">)</span> <span class="op">{</span></span>
|
|
<span class="r-in"> <span class="va">expr</span></span>
|
|
<span class="r-in"><span class="op">}</span></span>
|
|
<span class="r-in"></span>
|
|
<span class="r-in"><span class="co"># An example without ..stacktraceon/off.. manipulation.</span></span>
|
|
<span class="r-in"><span class="co"># The outer "try" is just to prevent example() from stopping.</span></span>
|
|
<span class="r-in"><span class="kw"><a href="https://rdrr.io/r/base/try.html" class="external-link">try</a></span><span class="op">(</span><span class="op">{</span></span>
|
|
<span class="r-in"> <span class="co"># The withLogErrors call ensures that stack traces are captured</span></span>
|
|
<span class="r-in"> <span class="co"># and that errors that bubble up are logged using warning().</span></span>
|
|
<span class="r-in"> <span class="fu">withLogErrors</span><span class="op">(</span><span class="op">{</span></span>
|
|
<span class="r-in"> <span class="co"># tryCatch and withVisible are just here to add some noise to</span></span>
|
|
<span class="r-in"> <span class="co"># the stack trace.</span></span>
|
|
<span class="r-in"> <span class="kw"><a href="https://rdrr.io/r/base/conditions.html" class="external-link">tryCatch</a></span><span class="op">(</span></span>
|
|
<span class="r-in"> <span class="fu"><a href="https://rdrr.io/r/base/withVisible.html" class="external-link">withVisible</a></span><span class="op">(</span><span class="op">{</span></span>
|
|
<span class="r-in"> <span class="fu">hiddenFunction</span><span class="op">(</span><span class="fu">visibleFunction2</span><span class="op">(</span><span class="op">)</span><span class="op">)</span></span>
|
|
<span class="r-in"> <span class="op">}</span><span class="op">)</span></span>
|
|
<span class="r-in"> <span class="op">)</span></span>
|
|
<span class="r-in"> <span class="op">}</span><span class="op">)</span></span>
|
|
<span class="r-in"><span class="op">}</span><span class="op">)</span></span>
|
|
<span class="r-wrn co"><span class="r-pr">#></span> <span class="warning">Warning: </span>Error in visibleFunction1: Kaboom!</span>
|
|
<span class="r-msg co"><span class="r-pr">#></span> shiny devmode - Turning on full stack trace. To disable, call `options(shiny.fullstacktrace = FALSE)`</span>
|
|
<span class="r-msg co"><span class="r-pr">#></span> <span style="color: #555555;">This message is displayed once every 8 hours.</span></span>
|
|
<span class="r-out co"><span class="r-pr">#></span> Error in visibleFunction1() : Kaboom!</span>
|
|
<span class="r-in"></span>
|
|
<span class="r-in"><span class="co"># Now the same example, but with ..stacktraceon/off.. to hide some</span></span>
|
|
<span class="r-in"><span class="co"># of the less-interesting bits (tryCatch and withVisible).</span></span>
|
|
<span class="r-in"><span class="fu">..stacktraceoff..</span><span class="op">(</span><span class="op">{</span></span>
|
|
<span class="r-in"> <span class="kw"><a href="https://rdrr.io/r/base/try.html" class="external-link">try</a></span><span class="op">(</span><span class="op">{</span></span>
|
|
<span class="r-in"> <span class="fu">withLogErrors</span><span class="op">(</span><span class="op">{</span></span>
|
|
<span class="r-in"> <span class="kw"><a href="https://rdrr.io/r/base/conditions.html" class="external-link">tryCatch</a></span><span class="op">(</span></span>
|
|
<span class="r-in"> <span class="fu"><a href="https://rdrr.io/r/base/withVisible.html" class="external-link">withVisible</a></span><span class="op">(</span></span>
|
|
<span class="r-in"> <span class="fu">hiddenFunction</span><span class="op">(</span></span>
|
|
<span class="r-in"> <span class="fu">..stacktraceon..</span><span class="op">(</span><span class="fu">visibleFunction2</span><span class="op">(</span><span class="op">)</span><span class="op">)</span></span>
|
|
<span class="r-in"> <span class="op">)</span></span>
|
|
<span class="r-in"> <span class="op">)</span></span>
|
|
<span class="r-in"> <span class="op">)</span></span>
|
|
<span class="r-in"> <span class="op">}</span><span class="op">)</span></span>
|
|
<span class="r-in"> <span class="op">}</span><span class="op">)</span></span>
|
|
<span class="r-in"><span class="op">}</span><span class="op">)</span></span>
|
|
<span class="r-wrn co"><span class="r-pr">#></span> <span class="warning">Warning: </span>Error in visibleFunction1: Kaboom!</span>
|
|
<span class="r-out co"><span class="r-pr">#></span> Error in visibleFunction1() : Kaboom!</span>
|
|
<span class="r-in"></span>
|
|
<span class="r-in"></span>
|
|
</code></pre></div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
|
|
<nav id="toc" data-toggle="toc" class="sticky-top"><h2 data-toc-skip>Contents</h2>
|
|
</nav></div>
|
|
</div>
|
|
|
|
|
|
<footer><div class="copyright">
|
|
<p></p><p>Developed by Winston Chang, Joe Cheng, JJ Allaire, Carson Sievert, Barret Schloerke, Yihui Xie, Jeff Allen, Jonathan McPherson, Alan Dipert, Barbara Borges.</p>
|
|
</div>
|
|
|
|
<div class="pkgdown">
|
|
<p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.5.</p>
|
|
</div>
|
|
|
|
</footer></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</body></html>
|
|
|