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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="brainbag" data-post="11" data-topic="1932" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/brainbag/48/2295_2.png" class="avatar"> brainbag:</div>
<blockquote>
<p>Although I love the concept, I found some issues with the implementation in practice for user errors, which is where this pattern is intended to be used. In particular:</p>
<p>not all functions return the same shape.<br>
one of my own functions that returned {:ok, :name, %metadata{}} which wouldn’t fit.<br>
some of the Elixir functions I needed didn’t return an error tuple. Map.fetch/2 for example just returns :error.</p>
<p>Although it was nice to break free when an error happened, I found error handling unnecessarily difficult because rather than handling the :error in context, I was doing it somewhere down the line. Often this meant I had to reconstruct context in order to provide a meaningful message to the UI.</p>
<p>To resolve <span class="hashtag-raw">#1</span>, I decided to change how it measured the results and tested either the result == :error || elem(result, 0) == :error, and any other result was just passed through. This worked better for me and allowed for the shapes to be different. It could be expanded to capture more errors, but it still assumes that it would know all error conditions.</p>
<p>Overall, after using it for a while, it felt more like I was using try/catchor GOTO for flow control, which I am not fond of. I found it to basically be just a prettier but less comprehensible/usable version ofwith.</p>
<p>I still love the idea of a flow chart for flow control, though!</p>
</blockquote>
</aside>
<aside class="quote no-group" data-username="Crowdhailer" data-post="10" data-topic="1932" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/crowdhailer/48/2438_2.png" class="avatar"> Crowdhailer:</div>
<blockquote>
<p>Would you have a use for any of the other concepts, such as the tee. I haven’t noticed them missing from my code. I think it might be an 80/20 rule. ~&gt;&gt; gives the vast majority of the benefits and the rest are just minor improvements</p>
</blockquote>
</aside>
<p>I agree with both of these comments wholeheartedly. This is why I use <code>with</code> statements prodigiously in my code, but I think <code>OK</code> really shines <img src="https://forum.elixirforum.com/images/emoji/apple/sunny.png?v=15" title=":sunny:" class="emoji" alt=":sunny:" loading="lazy" width="20" height="20">  in the builder use case as I mentioned above.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="12767" data-batch-url="/posts/batch_likers">
                        1
                      </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/ok-elegant-error-handling-for-elixir-pipelines-version-1-0-released/1932/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-12767" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="12767"
                     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="12768" data-post-id="12768">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/brainbag" rel="nofollow">@brainbag</a></p>
<ol>
<li>Have you looked at the <a href="https://hex.pm/packages/exceptional" rel="nofollow">exceptional</a> library on hex.pm?  It includes the functionality of ‘OK’ here as well as more to handle different shapes (handles <code>:ok</code>/<code>:error</code> 2-tuples, however you can integrate in more shape handlers, handles exceptions, handles raw values, and can convert between them all)) and has support for a new error handling paradigm (which I think is ingeniously simple/wonderful, but that is the story for another thread, but it is returning raw values or returning (not raising) exceptions).</li>
</ol>
<p>For just ‘ok’ 2-tuple handling I think this library handles its purpose wonderfully.  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="12768" 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/ok-elegant-error-handling-for-elixir-pipelines-version-1-0-released/1932/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-12768" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="12768"
                     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 #12"></div>
  </section>
</div>
    <div class="postbit" id="12781" data-post-id="12781">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Crowdhailer" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Crowdhailer/120/2438_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Crowdhailer
                    <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 class="user-title">
									<span>Creator of Raxx</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>All interesting points. I’ve run across a some of them but not all.</p>
<blockquote>
<p><a class="mention" href="/u/brainbag" rel="nofollow">@brainbag</a><br>
some of the Elixir functions I needed didn’t return an error tuple. <code>Map.fetch/2</code> for example just returns <code>:error</code>.</p>
</blockquote>
<p>This one annoys me the most. I would happily petition away to have this changed to <code>{:error, :not_found}</code> to match convention. In reality if I care enough I just wrap any functions like that.</p>
<blockquote>
<p><a class="mention" href="/u/brainbag" rel="nofollow">@brainbag</a><br>
one of my own functions that returned <code>{:ok, :name, %metadata{}}</code> which wouldn’t fit.</p>
</blockquote>
<p>why not create something like <code>response = %{name: :name, meta: %metadata{}</code>. If you have more than one extra thing in the tuple it wouldn’t be clear which is to pass to the next function. and the one that was not passed would be lost for ever.</p>
<p>Interesting point about handling errors out of context which is essential the goal of many error handling strategies.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="12781" data-batch-url="/posts/batch_likers">
                        1
                      </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/ok-elegant-error-handling-for-elixir-pipelines-version-1-0-released/1932/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-12781" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="12781"
                     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 #13"></div>
  </section>
</div>
    <div class="postbit" id="12782" data-post-id="12782">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Crowdhailer" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Crowdhailer/120/2438_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Crowdhailer
                    <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 class="user-title">
									<span>Creator of Raxx</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks <a class="mention" href="/u/overminddl1" rel="nofollow">@OvermindDL1</a> <img src="https://forum.elixirforum.com/images/emoji/apple/relaxed.png?v=15" title=":relaxed:" class="emoji" alt=":relaxed:" loading="lazy" width="20" height="20">. I should probably tag a 1.0 release and move on to another project.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="12782" data-batch-url="/posts/batch_likers">
                        1
                      </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/ok-elegant-error-handling-for-elixir-pipelines-version-1-0-released/1932/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-12782" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="12782"
                     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 #14"></div>
  </section>
</div>
    <div class="postbit" id="12995" data-post-id="12995">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Crowdhailer" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Crowdhailer/120/2438_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Crowdhailer
                    <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 class="user-title">
									<span>Creator of Raxx</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Just pushed a 1.0 release to <a href="https://hex.pm/packages/ok" rel="nofollow">hex</a>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="12995" data-batch-url="/posts/batch_likers">
                        4
                      </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/ok-elegant-error-handling-for-elixir-pipelines-version-1-0-released/1932/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-12995" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="12995"
                     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 #15"></div>
  </section>
</div>
    <div class="postbit" id="18442" data-post-id="18442">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Crowdhailer" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Crowdhailer/120/2438_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Crowdhailer
                    <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 class="user-title">
									<span>Creator of Raxx</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Just pushed up a possible extension to <a href="https://github.com/CrowdHailer/OK" rel="noopener nofollow ugc">OK</a> which gives if result blocks inspired by scala for comprehensions.</p>
<p>It allows you to match within the value so you could possibly solve the metadata problem by writing the following.<br>
requires first function to return <code>{:ok, {data, metadata}}</code></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">OK.try do
  {data, metadata} &lt;- first_function_with_errors
  _ &lt;- second_function_with_errors(data)
end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="18442" data-batch-url="/posts/batch_likers">
                        2
                      </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/ok-elegant-error-handling-for-elixir-pipelines-version-1-0-released/1932/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-18442" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="18442"
                     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>