Priority
High
Summary
sendDataToApi() assumes that every Ollama response contains valid outer JSON, a string-valued response field, and valid model-generated JSON.
Several normal failures can therefore raise unhandled Lua exceptions:
- Ollama is unavailable.
- Ollama returns an HTTP error.
- The selected model rejects image input.
- The outer API response is malformed.
response_data.response is missing or has the wrong type.
- The model response is not valid JSON.
- Markdown cleanup encounters a nil value.
The current failure path also returns a string while callers assume the result is a table.
Relevant code
lightroom-llama.lrplugin/LrLlama.lua
local response_data = JSON:decode(response)
local rawResponse = response_data.response
rawResponse = string.gsub(rawResponse, ...)
local response_json = JSON:decode(rawResponse)
return response_json
Failure path:
return "Error: Failed to send data to the API."
Caller:
props.title = apiResponse.title
props.caption = apiResponse.caption
Expected behavior
Every Ollama or parsing failure should leave the dialog operational and provide a useful error message.
Implementation notes
Introduce a consistent result contract, for example:
{
success = true,
data = {
title = "...",
caption = "...",
keywords = {}
}
}
or:
{
success = false,
error = "Ollama returned invalid JSON."
}
Protect JSON operations with pcall() and validate each layer before continuing.
Validate:
- HTTP response exists.
- HTTP status indicates success.
- Outer response decodes to a table.
response exists and is a string.
- Model response decodes to a table.
Acceptance criteria
Priority
High
Summary
sendDataToApi()assumes that every Ollama response contains valid outer JSON, a string-valuedresponsefield, and valid model-generated JSON.Several normal failures can therefore raise unhandled Lua exceptions:
response_data.responseis missing or has the wrong type.The current failure path also returns a string while callers assume the result is a table.
Relevant code
lightroom-llama.lrplugin/LrLlama.luaFailure path:
Caller:
Expected behavior
Every Ollama or parsing failure should leave the dialog operational and provide a useful error message.
Implementation notes
Introduce a consistent result contract, for example:
{ success = true, data = { title = "...", caption = "...", keywords = {} } }or:
{ success = false, error = "Ollama returned invalid JSON." }Protect JSON operations with
pcall()and validate each layer before continuing.Validate:
responseexists and is a string.Acceptance criteria
responsefields produce a recoverable error.