Fix config file loading and MQTT connection error handling
Config file loading fixes: - Fix tilde expansion in config paths (~/.config/systant/systant.toml) - Add detailed debug logging for config file search paths - Properly expand home directory paths with System.user_home() MQTT connection improvements: - Add clearer connection status logging with broker host:port - Improve error handling in connection callback - Better error messages when connection fails or is lost - More detailed initial connection logging These fixes address production deployment issues where config files aren't found and MQTT connection errors aren't properly reported. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8bbf91f25f
commit
505aede8d3
@ -171,9 +171,26 @@ defmodule Systant.Config do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp find_config_file do
|
defp find_config_file do
|
||||||
@default_config_paths
|
expanded_paths = @default_config_paths |> Enum.map(&expand_config_path/1)
|
||||||
|> Enum.map(&Path.expand/1)
|
|
||||||
|> Enum.find(&File.exists?/1)
|
Logger.debug("Searching for config files at: #{inspect(expanded_paths)}")
|
||||||
|
|
||||||
|
case Enum.find(expanded_paths, &File.exists?/1) do
|
||||||
|
nil ->
|
||||||
|
Logger.debug("No config file found, checked: #{inspect(expanded_paths)}")
|
||||||
|
nil
|
||||||
|
path ->
|
||||||
|
Logger.debug("Found config file at: #{path}")
|
||||||
|
path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp expand_config_path("~" <> rest) do
|
||||||
|
home = System.user_home()
|
||||||
|
Path.join(home, rest)
|
||||||
|
end
|
||||||
|
defp expand_config_path(path) do
|
||||||
|
Path.expand(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp apply_env_overrides(config) do
|
defp apply_env_overrides(config) do
|
||||||
|
|||||||
@ -16,6 +16,7 @@ defmodule Systant.MqttClient do
|
|||||||
mqtt_config = Systant.Config.mqtt_config(app_config)
|
mqtt_config = Systant.Config.mqtt_config(app_config)
|
||||||
|
|
||||||
Logger.info("Starting MQTT client with config: #{inspect(mqtt_config)}")
|
Logger.info("Starting MQTT client with config: #{inspect(mqtt_config)}")
|
||||||
|
Logger.info("Attempting to connect to MQTT broker at #{mqtt_config.host}:#{mqtt_config.port}")
|
||||||
|
|
||||||
# Store both configs for later use
|
# Store both configs for later use
|
||||||
state_config = %{
|
state_config = %{
|
||||||
|
|||||||
@ -18,11 +18,15 @@ defmodule Systant.MqttHandler do
|
|||||||
def connection(status, state) do
|
def connection(status, state) do
|
||||||
case status do
|
case status do
|
||||||
:up ->
|
:up ->
|
||||||
Logger.info("MQTT connection established")
|
Logger.info("MQTT connection established successfully")
|
||||||
:down ->
|
:down ->
|
||||||
Logger.warning("MQTT connection lost")
|
Logger.error("MQTT connection lost - check MQTT broker availability and configuration")
|
||||||
:terminating ->
|
:terminating ->
|
||||||
Logger.info("MQTT connection terminating")
|
Logger.info("MQTT connection terminating")
|
||||||
|
{:error, reason} ->
|
||||||
|
Logger.error("MQTT connection failed: #{inspect(reason)}")
|
||||||
|
other ->
|
||||||
|
Logger.error("MQTT connection status unknown: #{inspect(other)}")
|
||||||
end
|
end
|
||||||
{:ok, state}
|
{:ok, state}
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user