From abcf7dbfe502b25ffcef367d848b3a8e4fe803d3 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 30 Jun 2024 12:45:23 +1200 Subject: [PATCH] sqliteclidriver: better bubble up stderr errors --- sqliteclidriver/eventcmd.go | 16 ++++++++++++++++ sqliteclidriver/sqliteclidriver.go | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/sqliteclidriver/eventcmd.go b/sqliteclidriver/eventcmd.go index 43d8bfc..d2c00f3 100644 --- a/sqliteclidriver/eventcmd.go +++ b/sqliteclidriver/eventcmd.go @@ -18,6 +18,22 @@ type processEvent struct { err error } +func (pe processEvent) Error() string { + if pe.err != nil { + return pe.err.Error() + } + + if pe.evtype == evtypeStderr { + return string(pe.data) + } + + return "" +} + +func (pe processEvent) Unwrap() error { + return pe.err +} + // func ExecEvents(cmd *exec.Cmd) (<-chan processEvent, io.WriteCloser, error) { diff --git a/sqliteclidriver/sqliteclidriver.go b/sqliteclidriver/sqliteclidriver.go index a43da5e..3adf550 100644 --- a/sqliteclidriver/sqliteclidriver.go +++ b/sqliteclidriver/sqliteclidriver.go @@ -251,10 +251,11 @@ func (s *SCStmt) Query(args []driver.Value) (driver.Rows, error) { pw.CloseWithError(msg.err) return } + } else { // Anything else (process event / stderr) // Throw - pw.CloseWithError(fmt.Errorf("other thing %#v", msg)) + pw.CloseWithError(msg) return }