Skip to content

Commit 582ae3b

Browse files
committed
Fix error handling when no screenshots are available
1 parent 4793a46 commit 582ae3b

3 files changed

Lines changed: 79 additions & 6 deletions

File tree

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ It lets you **inspect logs, variables, performance metrics, and errors in real-t
2525
1. **Download Feather**
2626

2727
- Download the latest release from the [releases page](https://github.com/Kyonru/feather/releases)
28+
- Copy the `feather/` folder and put it in your project folder
2829
- Or install it via [Luarocks](https://luarocks.org/modules/kyonru/feather)
2930

3031
```bash
@@ -34,7 +35,7 @@ It lets you **inspect logs, variables, performance metrics, and errors in real-t
3435
1. **Require Feather**
3536

3637
```lua
37-
local Feather = require "feather"
38+
local Feather = require "feather" -- or the location of the feather folder
3839
```
3940

4041
---
@@ -157,6 +158,64 @@ Feather will automatically capture and log errors in real-time. You can also man
157158

158159
Feather comes with a plugin system that allows you to extend its functionality with custom data inspectors. Check out the [Feather Plugins](docs/plugins.md) repository for more information.
159160

161+
### TL;DR
162+
163+
Minimal example of a debugger file to load feather
164+
165+
```lua
166+
-- debugger.lua
167+
local FeatherDebugger = require("lib.feather")
168+
local FeatherPluginManager = require("lib.feather.plugin_manager")
169+
local LuaStateMachinePlugin = require("lib.feather.plugins.state-machine")
170+
local HumpSignalPlugin = require("lib.feather.plugins.signal")
171+
local ScreenshotPlugin = require("lib.feather.plugins.screenshots")
172+
173+
local debugger = {}
174+
175+
function debugger:load()
176+
debugger.feather = FeatherDebugger({
177+
debug = true, -- Make sure to only run while on development
178+
apiKey = "debugger",
179+
wrapPrint = true,
180+
defaultObservers = true,
181+
captureScreenshot = true,
182+
autoRegisterErrorHandler = true,
183+
errorWait = 10,
184+
baseDir = "game",
185+
plugins = {
186+
FeatherPluginManager.createPlugin(LuaStateMachinePlugin, "lua-state-machine", {
187+
--- https://github.com/kyleconroy/lua-state-machine
188+
machine = StateMachine,
189+
}),
190+
FeatherPluginManager.createPlugin(HumpSignalPlugin, "hump.signal", {
191+
-- https://hump.readthedocs.io/en/latest/signal.html
192+
signal = Signal,
193+
register = {
194+
"emit",
195+
"register",
196+
"remove",
197+
"emitPattern",
198+
"registerPattern",
199+
"removePattern",
200+
"clearPattern",
201+
},
202+
}),
203+
FeatherPluginManager.createPlugin(ScreenshotPlugin, "screenshots", {
204+
screenshotDirectory = "screenshots", -- output folder for captures
205+
fps = 60, -- frames per second for GIFs
206+
gifDuration = 5, -- default duration of GIFs in seconds
207+
}),
208+
},
209+
})
210+
end
211+
212+
function debugger:update(dt)
213+
debugger.feather:update(dt)
214+
end
215+
216+
return debugger
217+
```
218+
160219
## Recommendations
161220

162221
### Security

src-lua/feather/init.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ function Feather:init(config)
109109
local selfRef = self -- capture `self` to avoid upvalue issues
110110

111111
function love.errorhandler(msg)
112+
if not msg then
113+
msg = "Unknown error"
114+
end
115+
112116
selfRef:__onerror(msg, true) -- Log the error first
113117

114118
local function isDelivered()

src-lua/feather/plugins/logger.lua

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,23 @@ function FeatherLogger:log(line, screenshot)
9696
return
9797
end
9898

99-
if screenshot then
100-
local fileData = self.lastScreenshot:encode("png")
101-
local pngBytes = fileData:getString()
99+
if screenshot and self.captureScreenshot then
100+
local takeScreenshot = function()
101+
if not self.lastScreenshot then
102+
return
103+
end
104+
105+
local fileData = self.lastScreenshot:encode("png")
106+
local pngBytes = fileData:getString()
102107

103-
local b64 = love.data.encode("string", "base64", pngBytes)
108+
local b64 = love.data.encode("string", "base64", pngBytes)
109+
line.screenshot = b64
110+
end
104111

105-
line.screenshot = b64
112+
local result, err = pcall(takeScreenshot)
113+
if not result then
114+
print("Error capturing screenshot: " .. tostring(err))
115+
end
106116
end
107117

108118
line.id = tostring(os.time()) .. "-" .. tostring(#self.logs + 1)

0 commit comments

Comments
 (0)