<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="229462" data-post-id="229462">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="thiagomajesk" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/thiagomajesk/120/31904_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  thiagomajesk
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="jeremyjh" data-post="10" data-topic="43255">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jeremyjh/48/5995_2.png" class="avatar"> jeremyjh:</div>
<blockquote>
<p>exceptions would only happen for things like timeouts or migrations that haven’t run typically.</p>
</blockquote>
</aside>
<p>Or from op’s example, an <code>insert_all</code> that raises a constraint error, which means it won’t treat “exceptional” (pun intended) cases at all, so you have to be explicit about the failing cases - got it.</p>
<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="11" data-topic="43255">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>Non-bang functions never means it will never raise. For example, pass an integer to File.read/1. They will return tagged tuples for some class of errors that are up to the library to decide.</p>
</blockquote>
</aside>
<p>Hey <a class="mention" href="/u/josevalim" rel="nofollow">@josevalim</a>, yes of course! I think that the “tricky part” here (hence OP’s question), is that the <code>transaction/2</code> spec shows that it returns an error tuple. So one could assume it should be safe at a first glance. But again, like was shown in the thread, the other part is also documented.</p>
<p>From how the naming convention is phrased, it gives the impression that it’s always one <strong>or</strong> the other (but again, we don’t have a paired function here as well):</p>
<blockquote>
<p>Many functions come in pairs, such as <a href="https://hexdocs.pm/elixir/master/File.html#read/1" rel="noopener nofollow ugc"><code>File.read/1</code></a> and <a href="https://hexdocs.pm/elixir/master/File.html#read!/1" rel="noopener nofollow ugc"><code>File.read!/1</code></a>. <a href="https://hexdocs.pm/elixir/master/File.html#read/1" rel="noopener nofollow ugc"><code>File.read/1</code></a> will return a success or failure tuple, whereas <a href="https://hexdocs.pm/elixir/master/File.html#read!/1" rel="noopener nofollow ugc"><code>File.read!/1</code></a> will return a plain value or else raise an exception:</p>
</blockquote>
<p>So, this use case signals to me is that is perfectly possible to have a “”“unsafe”“” function that still returns an error tuple, is that right?</p>
<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="11" data-topic="43255">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>Plus transaction/2 is running your code via a function, so we shouldn’t compare it with File.read/1. A more apt comparison here would be File.open/2, which also doesn’t handle your own exceptions inside the function either.</p>
</blockquote>
</aside>
<p>Yes, that was a poor example. I didn’t understand what <a class="mention" href="/u/jeremyjh" rel="nofollow">@jeremyjh</a> meant by “thunk” in the previous comment. I agree it is not the same use case. That helped clearing things out a bit.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="229462" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/why-transaction-2-raises-an-exception-instead-of-a-return-tuple/43255/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-229462" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="229462"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="230823" data-post-id="230823">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="madili" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/madili/120/23676_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  madili
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi guys, thanks so much for the answers so far. It was possible to have a better understanding of <code>transaction/2</code>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="230823" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/why-transaction-2-raises-an-exception-instead-of-a-return-tuple/43255/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-230823" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="230823"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>