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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Adzz" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Adzz/120/10743_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Adzz
                    <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">
								<h1><a name="p-246460-new-versions-released-1" class="anchor" href="#p-246460-new-versions-released-1" aria-label="Heading link" rel="nofollow"></a>New Version(s) Released!</h1>
<h2><a name="p-246460-h-029-2" class="anchor" href="#p-246460-h-029-2" aria-label="Heading link" rel="nofollow"></a>0.2.9</h2>
<h3><a name="p-246460-improvement-3" class="anchor" href="#p-246460-improvement-3" aria-label="Heading link" rel="nofollow"></a>Improvement</h3>
<p>Allows for using a MFA tuple ({module, function, arguments}) as a casting function in a data schema. The value extracted from the input data will be set as the first argument in the arguments list.</p>
<h2><a name="p-246460-h-028-4" class="anchor" href="#p-246460-h-028-4" aria-label="Heading link" rel="nofollow"></a>0.2.8</h2>
<h3><a name="p-246460-improvement-5" class="anchor" href="#p-246460-improvement-5" aria-label="Heading link" rel="nofollow"></a>Improvement</h3>
<p>Improve the error message when the cast function does not return an okay tuple.</p>
<h2><a name="p-246460-h-027-6" class="anchor" href="#p-246460-h-027-6" aria-label="Heading link" rel="nofollow"></a>0.2.7</h2>
<h3><a name="p-246460-improvement-7" class="anchor" href="#p-246460-improvement-7" aria-label="Heading link" rel="nofollow"></a>Improvement</h3>
<p>Bump ex_doc to get newer looking docs.</p>
<h2><a name="p-246460-h-026-8" class="anchor" href="#p-246460-h-026-8" aria-label="Heading link" rel="nofollow"></a>0.2.6</h2>
<h3><a name="p-246460-bug-fix-9" class="anchor" href="#p-246460-bug-fix-9" aria-label="Heading link" rel="nofollow"></a>Bug fix</h3>
<p>Fix schema validations and error message.</p>
<p>We were not allowing valid schema syntax for an inline schema (ie a runtime schema that is provided at compile time), and our error message was wrong.</p>
<p>Now we correctly allow:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">has_many: {:dep, "./Dep", {%{}, @place_schema}},
has_one: {:arrival, "./Arrival", {%{}, @place_schema}},
</code></pre>
<p>And similar.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="246460" 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/data-schema-declarative-schemas-for-data-transformations/44073/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-246460" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="246460"
                     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="249578" data-post-id="249578">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Adzz" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Adzz/120/10743_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Adzz
                    <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">
								<h1><a name="p-249578-new-version-released-1" class="anchor" href="#p-249578-new-version-released-1" aria-label="Heading link" rel="nofollow"></a>New Version Released</h1>
<h2><a name="p-249578-h-030-2" class="anchor" href="#p-249578-h-030-2" aria-label="Heading link" rel="nofollow"></a>0.3.0</h2>
<h3><a name="p-249578-improvement-3" class="anchor" href="#p-249578-improvement-3" aria-label="Heading link" rel="nofollow"></a>Improvement</h3>
<p>We now handle errors returned from cast functions by returning a <code>%DataSchema.Errors{}</code> for them, which will effectively point to the field that error’d. Previously we were only doing that for non null errors for some reason! to_struct now never returns <code>:error</code> only, meaning you can now immediately see what caused the error. See the example below:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  defmodule Author do
    import DataSchema, only: [data_schema: 1]
    data_schema(
      field: {:name, "name", fn _ -&gt; :error  end}
    )
  end

  defmodule Comment do
    import DataSchema, only: [data_schema: 1]
    data_schema(
      has_one: {:author, "author", Author}
    )
  end

  defmodule BlagPost do
    import DataSchema, only: [data_schema: 1]

    data_schema(
      field: {:content, "content", &amp;{:ok, to_string(&amp;1)}},
      has_many: {:comments, "comments", Comment},
    )
  end

input = %{
  "content" =&gt; "This is a blog post",
  "comments" =&gt; [
    %{"author" =&gt; %{"name" =&gt; "Ted"} }, 
    %{"author" =&gt; %{"name" =&gt; "Danson"} }
  ]
}
DataSchema.to_struct(input, BlagPost)
</code></pre>
<p>Will return:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">{:error,
 %DataSchema.Errors{
   errors: [
     comments: %DataSchema.Errors{
       errors: [
         author: %DataSchema.Errors{errors: [name: "There was an error!"]}
       ]
     }
   ]
 }}
</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="249578" 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/data-schema-declarative-schemas-for-data-transformations/44073/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-249578" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="249578"
                     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="249855" data-post-id="249855">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Adzz" data-post="13" data-topic="44073">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/adzz/48/10743_2.png" class="avatar"> Adzz:</div>
<blockquote>
<pre data-code-wrap="elixir"><code class="lang-elixir">%DataSchema.Errors{
   errors: [
</code></pre>
</blockquote>
</aside>
<p>Why do you use the key <code>:errors</code>? It looks redundant, adds noise and doesn’t look useful, but I may be failing to understand it’s propose.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="249855" 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/data-schema-declarative-schemas-for-data-transformations/44073/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-249855" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="249855"
                     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="249915" data-post-id="249915">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Adzz" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Adzz/120/10743_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Adzz
                    <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>It was “errors” because I was trying to leave room for the possibility of collecting all errors in the future.</p>
<p>Right now in data schema if a casting function returns <code>nil</code> when it shouldn’t or if it errors we halt the transformation completely and return an error.</p>
<p>A different approach would be to continue with the schema, but “collect” all other errors along the way. This approach is similar to what Ecto does. In that world you may have multiple errors at each level, hence the need for <code>:errors</code>. But I agree it seems overcomplicated for the library as is.</p>
<p>I could maybe change it and return <code>DataSchema.Errors</code> when (/if) we "collect errors and a <code>DataSchema.Error</code> when we “fail fast” so to speak…</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="249915" 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/data-schema-declarative-schemas-for-data-transformations/44073/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-249915" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="249915"
                     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="255557" data-post-id="255557">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Adzz" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Adzz/120/10743_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Adzz
                    <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>New Release! 0.3.1</p>
<p>This release adds three new public functions:</p>
<ul>
<li><code>DataSchema.to_runtime_schema/1</code></li>
<li><code>DataSchema.flatten_errors/1</code></li>
<li><code>DataSchema.to_error_tuple/1</code></li>
</ul>
<p>These allow for schema reflection and make working with errors easier.</p>
<p><a class="mention" href="/u/exadra37" rel="nofollow">@Exadra37</a> the error functions may be of interest to you.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="255557" 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/data-schema-declarative-schemas-for-data-transformations/44073/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-255557" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="255557"
                     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="260838" data-post-id="260838">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Adzz" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Adzz/120/10743_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Adzz
                    <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">
								<h2><a name="p-260838-new-version-043-1" class="anchor" href="#p-260838-new-version-043-1" aria-label="Heading link" rel="nofollow"></a>New Version 0.4.3</h2>
<h3><a name="p-260838-enhancements-2" class="anchor" href="#p-260838-enhancements-2" aria-label="Heading link" rel="nofollow"></a>Enhancements</h3>
<p>Two new options:</p>
<ul>
<li><code>:empty_values</code></li>
<li><code>:default</code></li>
</ul>
<p>They work in combination to allow you to specify things like <code>[]</code> as an “empty” value for a <code>:list_of</code> field for example.</p>
<p>You can then also specify a <code>:default</code> which will be used if the field is optional and resolves to an empty value.</p>
<p>For example:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  defmodule Sandwich do
    require DataSchema

    DataSchema.data_schema([
      field: {
        :created_at,
        "inserted_at", 
         &amp;Date.from_iso8601/1,
        optional?: true, empty_values: [nil], default: &amp;DateTime.utc_now/0
      },
    ])
  end
</code></pre>
<p><code>:empty_values</code> defaults to <code>[nil]</code>.</p>
<p>We also changed it so that the casting function is only called if the field is not empty for all fields, meaning you don’t need to guard against nil in your cast fns.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="260838" 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/data-schema-declarative-schemas-for-data-transformations/44073/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-260838" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="260838"
                     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 #16"></div>
  </section>
</div>
    <div class="postbit" id="263205" data-post-id="263205">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Adzz" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Adzz/120/10743_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Adzz
                    <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">
								<h2><a name="p-263205-new-version-050-1" class="anchor" href="#p-263205-new-version-050-1" aria-label="Heading link" rel="nofollow"></a>New Version 0.5.0</h2>
<p>This version provides much richer information when a casting function unexpectedly raises.</p>
<p>Often we write cast functions as modules that implement a <code>cast</code> function. This means if they raise the stacktrace unhelpfully points to that module and tells you nothing about which field in the schema blew up.</p>
<p>This release captures all unexpected raises in a cast function and re-raises a <code>DataSchema.CastFunctionError</code> with information about which field blew up.</p>
<p>This has proven very helpful for larger schemas.</p>
<p>The <code>DataSchema.CastFunctionError</code> wraps the exception that it catches meaning you can still pattern match on it if you wish to catch some exceptions yourself, for example:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">try do
  DataSchema.to_struct(my_input, MySchema)
rescue
  %DataSchema.CastFunctionError{wrapped_error: %RuntimeError{}} -&gt;
    Logger.error("Runtime Error!")
    ...
  error -&gt;
    reraise error, __STACKTRACE__
end
</code></pre>
<p>Example error message:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">     ** (DataSchema.CastFunctionError)

     Unexpected error when casting value "my_input_value"
     for field :comments in this part of the schema:

     list_of: {:comments, "comments", StringType},

     Full path to field was:

                Field  :comments in MySchema
     Under Field  :metadata in MyParentSchema

     The casting function raised the following error:

     ** (RuntimeError) An error occured!
</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="263205" 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/data-schema-declarative-schemas-for-data-transformations/44073/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-263205" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="263205"
                     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>