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
|
||||
|
||||
defp find_config_file do
|
||||
@default_config_paths
|
||||
|> Enum.map(&Path.expand/1)
|
||||
|> Enum.find(&File.exists?/1)
|
||||
expanded_paths = @default_config_paths |> Enum.map(&expand_config_path/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
|
||||
|
||||
defp apply_env_overrides(config) do
|
||||
|
||||
@ -16,6 +16,7 @@ defmodule Systant.MqttClient do
|
||||
mqtt_config = Systant.Config.mqtt_config(app_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
|
||||
state_config = %{
|
||||
|
||||
@ -18,11 +18,15 @@ defmodule Systant.MqttHandler do
|
||||
def connection(status, state) do
|
||||
case status do
|
||||
:up ->
|
||||
Logger.info("MQTT connection established")
|
||||
Logger.info("MQTT connection established successfully")
|
||||
:down ->
|
||||
Logger.warning("MQTT connection lost")
|
||||
Logger.error("MQTT connection lost - check MQTT broker availability and configuration")
|
||||
: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
|
||||
{:ok, state}
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user