<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2024:10:03</title>
        <description></description>
        <link>https://baszerr.eu/</link>
        <lastBuildDate>Wed, 08 Apr 2026 00:25:51 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://baszerr.eu/</link>
        </image>
        <item>
            <title>2024-10-03_-_better_error_handling_in_bash</title>
            <link>https://baszerr.eu/doku.php?id=blog:2024:10:03:2024-10-03_-_better_error_handling_in_bash</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;better_error_handling_in_bash&quot;&gt;2024-10-03 - better error handling in bash&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
when wiring &lt;a href=&quot;https://en.wikipedia.org/wiki/Bash (Unix shell)&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Bash (Unix shell)&quot;&gt;bash&lt;/a&gt; scripts i always use &lt;code&gt;set -eu -o pipefail&lt;/code&gt; to make sure any error that&amp;#039;s not explicitly handled is a hard fault. sometimes it&amp;#039;s however hard to find the exact line, thus i usually just preemptively add &lt;code&gt;set -x&lt;/code&gt; at the beginning, so that in case sth fails, i have a full context. it works, but it&amp;#039;s clearly ugly.
&lt;/p&gt;

&lt;p&gt;
there&amp;#039;s however a much nicer way of handling it – with &lt;code&gt;trap&lt;/code&gt;s.
&lt;/p&gt;

&lt;p&gt;
let&amp;#039;s take a sample starting code:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;&lt;span class=&quot;co0&quot;&gt;#!/bin/bash&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-eu&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-o&lt;/span&gt; pipefail
&amp;nbsp;
&lt;span class=&quot;kw3&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;hello, world&amp;quot;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;date&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;false&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;this is where we&#039;ll fail&amp;quot;&lt;/span&gt;
&lt;span class=&quot;kw3&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;never see me&amp;quot;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
the output is enigmatic:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;hello, world
Thu Oct  3 20:30:05 CEST 2024&lt;/pre&gt;

&lt;p&gt;
we never made it to the end. in shell &lt;code&gt;$?&lt;/code&gt; is &lt;code&gt;1&lt;/code&gt;, so the error is reported, but in a longer script – good luck finding what exactly failed!
&lt;/p&gt;

&lt;p&gt;
here&amp;#039;s how to do this in a better way:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;&lt;span class=&quot;co0&quot;&gt;#!/bin/bash&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-eu&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-o&lt;/span&gt; pipefail
&amp;nbsp;
on_error&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw3&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;ERROR: $0:&lt;span class=&quot;es2&quot;&gt;$BASH_LINENO&lt;/span&gt; failed with exit code $? on:&amp;quot;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;
  &lt;span class=&quot;kw3&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;  &lt;span class=&quot;es2&quot;&gt;$BASH_COMMAND&lt;/span&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw3&quot;&gt;trap&lt;/span&gt; on_error ERR
&amp;nbsp;
&lt;span class=&quot;co0&quot;&gt;# actual script goes here - same as before:&lt;/span&gt;
&lt;span class=&quot;kw3&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;hello, world&amp;quot;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;date&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;false&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;this is where we&#039;ll fail&amp;quot;&lt;/span&gt;
&lt;span class=&quot;kw3&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;never see me&amp;quot;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
and now the output is decodable, indeed:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;hello, world
Thu Oct  3 20:32:03 CEST 2024
ERROR: ./my_script:14 failed with exit code 1 on:
  false &amp;quot;this is where we&amp;#039;ll fail&amp;quot;&lt;/pre&gt;

&lt;p&gt;
now we get both nice output and a foot in the door, when things fail. it&amp;#039;s such a nice, simple feature – no idea why it&amp;#039;s not a common thing all over the place.
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Thu, 03 Oct 2024 18:34:10 +0000</pubDate>
        </item>
        <item>
            <title>2024-10-03_-_raspi_zero_w_1.x_vs._2</title>
            <link>https://baszerr.eu/doku.php?id=blog:2024:10:03:2024-10-03_-_raspi_zero_w_1.x_vs._2</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;raspi_zero_w_1x_vs_2&quot;&gt;2024-10-03 - RasPi Zero W 1.x vs. 2&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;https://en.wikipedia.org/wiki/Raspberry_Pi_Zero#Raspberry_Pi_Zero&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Raspberry_Pi_Zero#Raspberry_Pi_Zero&quot;&gt;RasPi Zero&lt;/a&gt; is a nice, little board running &lt;a href=&quot;https://en.wikipedia.org/wiki/linux&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/linux&quot;&gt;linux&lt;/a&gt;. for a simpler tasks, that do require a “real &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt;”, it&amp;#039;s a perfect choice, with an friendly price tag. some time ago i bough RasPi Zero 1.x W for a remote flashing tool (i&amp;#039;ll leave out details for &lt;a href=&quot;https://baszerr.eu/doku.php?id=blog:2024:11:24:2024-11-24_-_remote_flashing_embedded_device&quot; class=&quot;wikilink1&quot; title=&quot;blog:2024:11:24:2024-11-24_-_remote_flashing_embedded_device&quot; data-wiki-id=&quot;blog:2024:11:24:2024-11-24_-_remote_flashing_embedded_device&quot;&gt;another post&lt;/a&gt;). i needed WiFi-enabled one, but i was hesitating between series 1.x and 2. 1.x was a bit cheaper, but since it&amp;#039;s 32-bit, 1 core and thus far less capable, i figured out it will consume less current and went with this one.
&lt;/p&gt;

&lt;p&gt;
it turned out that i had some issues with connecting to my home WiFi. some APs worked, some did not. so i ended up using external (USB) WiFi card. problem solved. it did cost me an evening to figure out the root cause, though.
&lt;/p&gt;

&lt;p&gt;
since i do have version 2 as well, i decided to give it a shot, too. it connected to all WiFis i have flawlessly. that made me thinking – how much power do i really save by using 1.x instead of 2? here&amp;#039;s my results.
&lt;/p&gt;
&lt;div class=&quot;table sectionedit2&quot;&gt;&lt;table class=&quot;inline&quot;&gt;
	&lt;thead&gt;
	&lt;tr class=&quot;row0&quot;&gt;
		&lt;th class=&quot;col0&quot;&gt; RasPi version &lt;/th&gt;&lt;th class=&quot;col1&quot;&gt; workload &lt;/th&gt;&lt;th class=&quot;col2&quot;&gt; [V] &lt;/th&gt;&lt;th class=&quot;col3&quot;&gt; [A] &lt;/th&gt;&lt;th class=&quot;col4&quot;&gt; [W] &lt;/th&gt;
	&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tr class=&quot;row1&quot;&gt;
		&lt;td class=&quot;col0&quot; rowspan=&quot;2&quot;&gt; 1.x &lt;/td&gt;&lt;td class=&quot;col1&quot;&gt; idle &lt;/td&gt;&lt;td class=&quot;col2&quot;&gt; 5 &lt;/td&gt;&lt;td class=&quot;col3&quot;&gt; 0.12 &lt;/td&gt;&lt;td class=&quot;col4&quot;&gt; 0.6 &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row2&quot;&gt;
		&lt;td class=&quot;col0&quot;&gt; apt &lt;/td&gt;&lt;td class=&quot;col1&quot;&gt; 5 &lt;/td&gt;&lt;td class=&quot;col2&quot;&gt; 0.3 &lt;/td&gt;&lt;td class=&quot;col3&quot;&gt; 1.5 &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row3&quot;&gt;
		&lt;td class=&quot;col0&quot; rowspan=&quot;2&quot;&gt; 2 &lt;/td&gt;&lt;td class=&quot;col1&quot;&gt; idle &lt;/td&gt;&lt;td class=&quot;col2&quot;&gt; 5 &lt;/td&gt;&lt;td class=&quot;col3&quot;&gt; 0.1 &lt;/td&gt;&lt;td class=&quot;col4&quot;&gt; 0.5 &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row4&quot;&gt;
		&lt;td class=&quot;col0&quot;&gt; apt &lt;/td&gt;&lt;td class=&quot;col1&quot;&gt; 5 &lt;/td&gt;&lt;td class=&quot;col2&quot;&gt; 0.25 &lt;/td&gt;&lt;td class=&quot;col3&quot;&gt; 1.25 &lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;table&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;table&amp;quot;,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;1097-1266&amp;quot;} --&gt;
&lt;p&gt;
turned out that it does not matter if board is doing sth (1 core) or idling – both cases version 2 is more power efficient, despite being 64-bit (vs. 32-bit 1.x). version 2 is a pure win, at a minimal cost difference.
&lt;/p&gt;

&lt;p&gt;
more over - &lt;a href=&quot;https://en.wikipedia.org/wiki/ASLR&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/ASLR&quot;&gt;ASLR&lt;/a&gt; is almost worthless on 32-bit system nowadays, so 64-bit version is also a security win.
&lt;/p&gt;

&lt;p&gt;
i still have a couple of RasPis 1.x W on the shelve. will use them over time, for sure. but for new projects version 2 is the way to go. :)
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sun, 24 Nov 2024 20:20:18 +0000</pubDate>
        </item>
    </channel>
</rss>
