Homebrew postgres and psql error: could not connect to server icu4c error

10:36:54.086 [error] Postgrex.Protocol (#PID<0.522.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (127.0.0.1:5432): connection refused - :econnrefused

psql: error: could not connect to server: could not connect to server: No such file or directory<br>Is the server running locally and accepting<br>connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

Even if brew services restart postgres is successful, there may be an error occurring, view your log, which for me with homebrew’s install was tail -n 50 /usr/local/var/log/postgres.log. If you see something like the following, you may need to switch a package version back to something older:

dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.64.dylib<br>Referenced from: /usr/local/opt/postgresql/bin/postgres<br>Reason: image not found

For me, after an OS update, the icu4c package had been changed, so I needed to switch it back, using brew switch icu4c 64.2

Elixir Wallaby and Chromedriver issue: (RuntimeError) invalid session id

 1) feature does X (BaseApp.UIWeb.Test.Acceptance.TheTest)
     apps/ui/test/ui_web/acceptance/the_testexs:13
     ** (RuntimeError) invalid session id
     code: |> session_login()
     stacktrace:
       (wallaby) lib/wallaby/httpclient.ex:136: Wallaby.HTTPClient.check_for_response_errors/1
       (wallaby) lib/wallaby/httpclient.ex:56: Wallaby.HTTPClient.make_request/5
       (wallaby) lib/wallaby/webdriver_client.ex:254: Wallaby.WebdriverClient.visit/2
       (wallaby) lib/wallaby/driver/log_checker.ex:6: Wallaby.Driver.LogChecker.check_logs!/2
       (wallaby) lib/wallaby/browser.ex:963: Wallaby.Browser.visit/2
       (ui) test/support/acceptance/rivendell_wallaby_session.ex:73: Rivendell.UIWeb.Test.Support.Acceptance.RivendellWallabySession.session_login/1

The solution for this was to run: brew upgrade chromedriver (this used to be brew cask upgrade chromedriver). You may possibly need to update your chrome browser. The comments on this issue/repo were very helpful: https://github.com/elixir-wallaby/wallaby/issues/468.

Generally, it would seem it is a good idea to keep your chromedriver in sync with your updates to Chrome (run brew upgrade chromedriver when you update Chrome.

More general errors will likely be an issue with your local code as opposed to Wallaby or package dependencies 🙂 See: https://n8williams.com/devblog/general_dev/elixir-wallaby-uncaught-javascript-error

Getting the current date for a timezone with Elixir

Issue: Getting the (current or otherwise) date for a specific timezone can be involve some trickiness.

Example: I want to show the current date in New York, even though I reside in Austin, TX. If it is 12/11/2020 11:39 PM CT:

  • The display for NY data should show 12/12/2020
  • A display for Austin, TX would show 12/11/20202

One solution:

NOTE: When dealing with DateTimes to save to a database, leaving the microseconds on can cause issues. I’m surprised the DateTime result doesn’t default to the more compatible format (TBD on whether from Elixir or Timex). See https://github.com/riverrun/phauxth-example/issues/10