refactor #8

Manually merged
nex merged 0 commits from oddlid/sensebot-go:refactor into dev 2026-02-27 13:19:31 +00:00
Contributor

Here I've done some of the things I mentioned. I've mixed styles a bit, like some places (getInput) I check even fmt.F*f for errors, while other places I don't, so you can see what you prefer.
This first draft is just to see if you like this way of doing it, and to agree on a way forward.

Closes #7

Here I've done some of the things I mentioned. I've mixed styles a bit, like some places (getInput) I check even fmt.F*f for errors, while other places I don't, so you can see what you prefer. This first draft is just to see if you like this way of doing it, and to agree on a way forward. Closes #7
WIP: First sketch of refactoring cmd/sensebot
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
ab0109fd92
- Use one top level context for signalling
- Split up in smaller functions
- Return errors instead of panicking
@ -0,0 +60,4 @@
resp, err := mxClient.Login(
ctx,
&mautrix.ReqLogin{
Type: "m.login.password", // TODO: make constants for all JSON keys used?
Owner

Actually I think mautrix.AuthTypePassword already exists

Actually I think `mautrix.AuthTypePassword` already exists
Owner
[it does!](https://pkg.go.dev/maunium.net/go/mautrix#AuthType)
@ -0,0 +135,4 @@
content: make([]byte, len(prompt)),
}
res, err := login(context.TODO(), &in, &out)
Owner

context.TODO() instead of t.Context()?

`context.TODO()` instead of `t.Context()`?
Author
Contributor

Ah, nice! It's so "new" in Go that I wasn't aware of it. Sure will change!

Ah, nice! It's so "new" in Go that I wasn't aware of it. Sure will change!
Owner

Oh huh, it was added in Go 1.24, i didn't even realise it was that new 😅

Oh huh, it was added in Go 1.24, i didn't even realise it was that new 😅
Author
Contributor

Last I worked with Golang (1.5y ago), we were still on 1.21, so that's why it was "new" to me :P

Last I worked with Golang (1.5y ago), we were still on 1.21, so that's why it was "new" to me :P
@ -0,0 +129,4 @@
log.Warn().Msg("Received shutdown signal")
log.Info().Msg("Waiting for tasks to finish...")
wg.Wait()
Owner

this wg.Wait() has haunted me since it was added, since I didn't understand contexts at the time and I'm pretty sure has been the source of deadlocks during shutdown before. Up to you if you want to investigate the sanity of it in this PR, but if not I'll probably see if I can yank it later.

this `wg.Wait()` has haunted me since it was added, since I didn't understand contexts at the time and I'm pretty sure has been the source of deadlocks during shutdown before. Up to you if you want to investigate the sanity of it in this PR, but if not I'll probably see if I can yank it later.
Author
Contributor

I haven't actually run this yet, I've just changed stuff to a pattern I know usually works well. Since there's now only one top level context getting passed around, which will get cancelled on the given signals, this should work. But sure, it needs to be properly tested.

I haven't actually run this yet, I've just changed stuff to a pattern I know usually works well. Since there's now only one top level context getting passed around, which will get cancelled on the given signals, this *should* work. But sure, it needs to be properly tested.
Merge generateConfig and login
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
78dd6b4bba
Some more tests
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
ecfd5c14a8
Contexts and linter complaints
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
04a6fcd889
Reuse code
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
bb7ba7ba23
- Put common errors/constants/functions in the types package
- Fix most remaining linter complaints
- More context checks (eg. fail fast if cancelled)
Merge branch 'dev' into refactor
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
1ec3ecba48
# Conflicts:
#	pkg/sensebot/commands/cmd_get_membership_history.go
#	pkg/sensebot/commands/cmd_management.go
#	pkg/sensebot/commands/cmd_room_info.go
#	pkg/sensebot/commands/cmd_servers.go
#	pkg/statestore/statestore.go
#	pkg/tables/table.go
Resolve remaining lint complaints
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
0a39c8fa89
oddlid force-pushed refactor from 0a39c8fa89
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
to ee1a65d3ac
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
2026-01-27 10:09:53 +00:00
Compare
Create wrapper for fmt print/scan
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
307fe40263
Replacing direct calls to fmt.Fprintf/Fscanf with a wrapper that ignores
errors from these calls, but is still safe to use, and will not crash
with nil pointers.
First steps in removing the embedded context in CommandContext
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
a6cbbeae8a
Preparing FmtWrapper for move to separate package
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
d016dfd4e9
Moved embedded context out of CommandContext
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
2b1e1e386c
Changed commandRegistry.Register to return an error and moved panics to
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
82b5d25f74
the call sites
Made functions and variables private, where possible
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
0a6caf3fb3
Replace repeated calls to zerolog.Ctx with local cached instance where
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
b1e28d55f3
it makes sense
Made some functions private, and commented out unused code
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
e37db138f8
Merge branch 'dev' into refactor
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
bb4d5b3986
# Conflicts:
#	pkg/sensebot/client/client.go
#	pkg/sensebot/client/commandregistry.go
#	pkg/sensebot/commands/cmd_room_info.go
#	pkg/sensebot/commands/cmd_servers.go
#	pkg/statestore/statestore.go
Reverted a merge glitch, and added a Wait method to Paginator
All checks were successful
Build docker on push / docker (pull_request) Has been skipped
cb88ef40fc
Updated paginator
Some checks failed
Build docker on push / docker (pull_request) Has been skipped
Build docker on push / docker (push) Failing after 9s
8d73bf2d89
- Made fields private
- Added nil checks to public methods
nex changed title from WIP: refactor to refactor 2026-02-27 13:19:19 +00:00
nex manually merged commit 8d73bf2d89 into dev 2026-02-27 13:19:31 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nex/sensebot-go!8
No description provided.