<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: cawalch</title>
    <description>The latest articles on DEV Community by cawalch (@cawalch).</description>
    <link>https://dev.to/cawalch</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F539649%2Fba072784-b119-4dd2-84cf-a96e08a82355.jpeg</url>
      <title>DEV Community: cawalch</title>
      <link>https://dev.to/cawalch</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cawalch"/>
    <language>en</language>
    <item>
      <title>Config Validation</title>
      <dc:creator>cawalch</dc:creator>
      <pubDate>Sat, 03 Sep 2022 21:28:32 +0000</pubDate>
      <link>https://dev.to/cawalch/config-validation-1i1m</link>
      <guid>https://dev.to/cawalch/config-validation-1i1m</guid>
      <description>&lt;p&gt;You're trying out a new cli tool that solves a common problem you keep running into. Before you can start using it, you need to know how to configure it properly. Luckily the site has a ton of example configs. You copy one of the examples into your favorite editor and change out the values.&lt;/p&gt;

&lt;p&gt;You finally found the perfect tool to solve a problem that would have taken weeks of unplanned work if you had to it build yourself. Back at the command prompt you run the tool, and it spits out a short error message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;*&lt;/span&gt; ERR: unexpected argument &lt;span class="o"&gt;(&lt;/span&gt;undefined&lt;span class="o"&gt;)&lt;/span&gt; expected uint
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's strange. You probably mistyped something, so you go back to review the config. Nothing stands out as an issue, so you hop back over to the documentation. After a few minutes of reading and comparing the example with your config, you're stumped.&lt;/p&gt;

&lt;p&gt;You run a search for the error in the github repo for the tool. No results in Issues. Either you can post a question in the repo's Issues, or dig through the source to see what you're doing wrong. You decide it would be quicker to peek at the source for the config loader.&lt;/p&gt;

&lt;p&gt;Within five minutes you were able to trace the problem down to a recent commit. The change splits the host and port number out as separate required fields for the &lt;code&gt;remoteHost&lt;/code&gt; config option. You add &lt;code&gt;remotePort&lt;/code&gt; and try again. This time it starts up without issue. A little annoyed about the documentation being outdated, you're still grateful for the tool.&lt;/p&gt;

&lt;p&gt;In this scenario, it took less than 15 minutes of troubleshooting to get back on track. It's not uncommon for people to spend upwards of several DAYS trying to get their configurations working. Especially for more complex systems supporting numerous configuration file formats, environment variable settings, command-line arguments, and dynamic configurations.&lt;/p&gt;

&lt;p&gt;Application configuration should be treated the same as UI interactions. They should be validated before use, provide friendly error messages with context, and &lt;strong&gt;catch additional unsupported or unknown properties&lt;/strong&gt; instead of ignoring them. In addition, a DEBUG or verbose logging option should be supported to view the final resolved configuration the app is running. There are few things more frustrating than having to recreate immutable config files in a staging environment over and over by guessing what could be wrong. Are the secrets being loaded? Is that environment variable taking precedence over the static config option? What is actually loaded?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;*&lt;/span&gt; ERR: config &lt;span class="s1"&gt;'remoteHost'&lt;/span&gt; failed validation - unexpected characters &lt;span class="s2"&gt;":9093"&lt;/span&gt;
&lt;span class="k"&gt;*&lt;/span&gt; ERR: config &lt;span class="s1"&gt;'remotePort'&lt;/span&gt; missing required property
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would have pointed the user in the right direction.&lt;/p&gt;

&lt;p&gt;Instead of writing your own configuration validation, stick with a well established standard such as JSON Schema. Even if your app uses YAML, it is still a superset of JSON.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://json-schema.org/implementations.html#validators"&gt;JSON Schema Validators&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
    </item>
  </channel>
</rss>
