Skip to content

Use go 1.24 #842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI
on: [push, pull_request]
env:
go-version: "1.23.x"
go-version: "1.24.x"
jobs:
test:
name: Test
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.23
FROM golang:1.24

WORKDIR /usr/src/app

Expand Down
18 changes: 9 additions & 9 deletions channel_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,39 @@ const (
)

func ErrorResponseStatusCode() *clogs.LogError {
return clogs.NewLogError("response_status_code", "", "Unexpected response status code.")
return &clogs.LogError{Code: "response_status_code", Message: "Unexpected response status code."}
}

func ErrorResponseUnparseable(format string) *clogs.LogError {
return clogs.NewLogError("response_unparseable", "", "Unable to parse response as %s.", format)
return &clogs.LogError{Code: "response_unparseable", Message: fmt.Sprintf("Unable to parse response as %s.", format)}
}

func ErrorResponseUnexpected(expected string) *clogs.LogError {
return clogs.NewLogError("response_unexpected", "", "Expected response to be '%s'.", expected)
return &clogs.LogError{Code: "response_unexpected", Message: fmt.Sprintf("Expected response to be '%s'.", expected)}
}

func ErrorResponseValueMissing(key string) *clogs.LogError {
return clogs.NewLogError("response_value_missing", "", "Unable to find '%s' response.", key)
return &clogs.LogError{Code: "response_value_missing", Message: fmt.Sprintf("Unable to find '%s' response.", key)}
}

func ErrorMediaUnsupported(contentType string) *clogs.LogError {
return clogs.NewLogError("media_unsupported", "", "Unsupported attachment media type: %s.", contentType)
return &clogs.LogError{Code: "media_unsupported", Message: fmt.Sprintf("Unsupported attachment media type: %s.", contentType)}
}

// ErrorMediaUnresolveable is used when media is unresolveable due to the channel's specific requirements
func ErrorMediaUnresolveable(contentType string) *clogs.LogError {
return clogs.NewLogError("media_unresolveable", "", "Unable to find version of %s attachment compatible with channel.", contentType)
return &clogs.LogError{Code: "media_unresolveable", Message: fmt.Sprintf("Unable to find version of %s attachment compatible with channel.", contentType)}
}

func ErrorAttachmentNotDecodable() *clogs.LogError {
return clogs.NewLogError("attachment_not_decodable", "", "Unable to decode embedded attachment data.")
return &clogs.LogError{Code: "attachment_not_decodable", Message: "Unable to decode embedded attachment data."}
}

func ErrorExternal(code, message string) *clogs.LogError {
if message == "" {
message = fmt.Sprintf("Service specific error: %s.", code)
}
return clogs.NewLogError("external", code, message)
return &clogs.LogError{Code: "external", ExtCode: code, Message: message}
}

// ChannelLog stores the HTTP traces and errors generated by an interaction with a channel.
Expand Down Expand Up @@ -95,7 +95,7 @@ func newChannelLog(t clogs.LogType, ch Channel, r *httpx.Recorder, attached bool

// Deprecated: channel handlers should add user-facing error messages via .Error() instead
func (l *ChannelLog) RawError(err error) {
l.Error(clogs.NewLogError("", "", err.Error()))
l.Error(&clogs.LogError{Message: err.Error()})
}

func (l *ChannelLog) Channel() Channel {
Expand Down
2 changes: 1 addition & 1 deletion channel_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestChannelLog(t *testing.T) {
assert.EqualError(t, err, "unable to connect to server")

clog.HTTP(trace)
clog.Error(clogs.NewLogError("not_right", "", "Something not right"))
clog.Error(&clogs.LogError{Code: "not_right", Message: "Something not right"})
clog.RawError(errors.New("this is an error"))
clog.End()

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nyaruka/courier

go 1.23
go 1.24

require (
github.com/antchfx/xmlquery v1.4.3
Expand Down
4 changes: 2 additions & 2 deletions handlers/dialog360/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@

// if we have more than 10 quick replies, truncate and add channel error
if len(qrs) > 10 {
clog.Error(clogs.NewLogError("", "", "too many quick replies D3C supports only up to 10 quick replies"))
clog.Error(&clogs.LogError{Message: "too many quick replies D3C supports only up to 10 quick replies"})
qrs = qrs[:10]
}

Expand Down Expand Up @@ -437,7 +437,7 @@
payload.Type = "interactive"
// if we have more than 10 quick replies, truncate and add channel error
if len(qrs) > 10 {
clog.Error(clogs.NewLogError("", "", "too many quick replies D3C supports only up to 10 quick replies"))
clog.Error(&clogs.LogError{Message: "too many quick replies D3C supports only up to 10 quick replies"})

Check warning on line 440 in handlers/dialog360/handler.go

View check run for this annotation

Codecov / codecov/patch

handlers/dialog360/handler.go#L440

Added line #L440 was not covered by tests
qrs = qrs[:10]
}

Expand Down
2 changes: 1 addition & 1 deletion handlers/dialog360/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"list","body":{"text":"Interactive List Msg"},"action":{"button":"Menu","sections":[{"rows":[{"id":"0","title":"ROW1"},{"id":"1","title":"ROW2"},{"id":"2","title":"ROW3"},{"id":"3","title":"ROW4"},{"id":"4","title":"ROW5"},{"id":"5","title":"ROW6"},{"id":"6","title":"ROW7"},{"id":"7","title":"ROW8"},{"id":"8","title":"ROW9"},{"id":"9","title":"ROW10"}]}]}}}`,
}},
ExpectedExtIDs: []string{"157b5e14568e8"},
ExpectedLogErrors: []*clogs.LogError{clogs.NewLogError("", "", "too many quick replies D3C supports only up to 10 quick replies")},
ExpectedLogErrors: []*clogs.LogError{&clogs.LogError{Message: "too many quick replies D3C supports only up to 10 quick replies"}},
},
{
Label: "Interactive List Message Send In Spanish",
Expand Down
4 changes: 2 additions & 2 deletions handlers/meta/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@

// if we have more than 10 quick replies, truncate and add channel error
if len(qrs) > 10 {
clog.Error(clogs.NewLogError("", "", "too many quick replies WAC supports only up to 10 quick replies"))
clog.Error(&clogs.LogError{Message: "too many quick replies WAC supports only up to 10 quick replies"})
qrs = qrs[:10]
}

Expand Down Expand Up @@ -937,7 +937,7 @@

// if we have more than 10 quick replies, truncate and add channel error
if len(qrs) > 10 {
clog.Error(clogs.NewLogError("", "", "too many quick replies WAC supports only up to 10 quick replies"))
clog.Error(&clogs.LogError{Message: "too many quick replies WAC supports only up to 10 quick replies"})

Check warning on line 940 in handlers/meta/handlers.go

View check run for this annotation

Codecov / codecov/patch

handlers/meta/handlers.go#L940

Added line #L940 was not covered by tests
qrs = qrs[:10]
}

Expand Down
2 changes: 1 addition & 1 deletion handlers/meta/whataspp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ var whatsappOutgoingTests = []OutgoingTestCase{
Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"list","body":{"text":"Interactive List Msg"},"action":{"button":"Menu","sections":[{"rows":[{"id":"0","title":"ROW1"},{"id":"1","title":"ROW2"},{"id":"2","title":"ROW3"},{"id":"3","title":"ROW4"},{"id":"4","title":"ROW5"},{"id":"5","title":"ROW6"},{"id":"6","title":"ROW7"},{"id":"7","title":"ROW8"},{"id":"8","title":"ROW9"},{"id":"9","title":"ROW10"}]}]}}}`,
}},
ExpectedExtIDs: []string{"157b5e14568e8"},
ExpectedLogErrors: []*clogs.LogError{clogs.NewLogError("", "", "too many quick replies WAC supports only up to 10 quick replies")},
ExpectedLogErrors: []*clogs.LogError{&clogs.LogError{Message: "too many quick replies WAC supports only up to 10 quick replies"}},
},
{
Label: "Interactive List Message Send In Spanish",
Expand Down
2 changes: 1 addition & 1 deletion handlers/slack/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (h *handler) sendTextMsgPart(msg courier.MsgOut, token string, clog *courie
if err != nil {
return courier.ErrResponseContent
}
clog.Error(clogs.NewLogError("", "", errDescription))
clog.Error(&clogs.LogError{Message: errDescription})
return courier.ErrFailedWithReason("", errDescription)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion handlers/slack/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ var defaultSendTestCases = []OutgoingTestCase{
Body: `{"channel":"U0123ABCDEF","text":"Hello"}`,
}},
ExpectedError: courier.ErrFailedWithReason("", "invalid_auth"),
ExpectedLogErrors: []*clogs.LogError{clogs.NewLogError("", "", "invalid_auth")},
ExpectedLogErrors: []*clogs.LogError{&clogs.LogError{Message: "invalid_auth"}},
},
{
Label: "Response Unexpected",
Expand Down
2 changes: 1 addition & 1 deletion handlers/telesom/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (h *handler) Send(ctx context.Context, msg courier.MsgOut, res *courier.Sen
}

if !strings.Contains(string(respBody), "Success") {
clog.Error(clogs.NewLogError("", "", "Received invalid response content: %s", string(respBody)))
clog.Error(&clogs.LogError{Message: fmt.Sprintf("Received invalid response content: %s", string(respBody))})
return courier.ErrResponseContent
}
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/telesom/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ var defaultSendTestCases = []OutgoingTestCase{
Form: url.Values{"msg": {"Simple Message"}, "to": {"0788383383"}, "from": {"2020"}, "key": {"D69BB824F88F20482B94ECF3822EBD84"}},
Headers: map[string]string{"Content-Type": "application/x-www-form-urlencoded"},
}},
ExpectedLogErrors: []*clogs.LogError{clogs.NewLogError("", "", "Received invalid response content: <return>Missing</return>")},
ExpectedLogErrors: []*clogs.LogError{&clogs.LogError{Message: "Received invalid response content: <return>Missing</return>"}},
ExpectedError: courier.ErrResponseContent,
},
}
Expand Down
4 changes: 2 additions & 2 deletions sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
status.SetStatus(MsgStatusFailed)
}

clog.Error(clogs.NewLogError(serr.clogCode, serr.clogExtCode, serr.clogMsg))
clog.Error(&clogs.LogError{Code: serr.clogCode, ExtCode: serr.clogExtCode, Message: serr.clogMsg})

// if handler returned ErrContactStopped need to write a stop event
if serr == ErrContactStopped {
Expand All @@ -401,7 +401,7 @@

status.SetStatus(MsgStatusErrored)

clog.Error(clogs.NewLogError("internal_error", "", "An internal error occured."))
clog.Error(&clogs.LogError{Code: "internal_error", Message: "An internal error occured."})

Check warning on line 404 in sender.go

View check run for this annotation

Codecov / codecov/patch

sender.go#L404

Added line #L404 was not covered by tests
}

return status
Expand Down
2 changes: 1 addition & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestOutgoing(t *testing.T) {
// and we should have a channel log with redacted errors and traces
assert.Len(t, mb.WrittenChannelLogs(), 1)
clog := mb.WrittenChannelLogs()[0]
assert.Equal(t, []*clogs.LogError{clogs.NewLogError("seeds", "", "contains ********** seeds")}, clog.Errors)
assert.Equal(t, []*clogs.LogError{&clogs.LogError{Code: "seeds", Message: "contains ********** seeds"}}, clog.Errors)
assert.True(t, clog.Attached())
assert.Len(t, clog.HttpLogs, 1)

Expand Down
2 changes: 1 addition & 1 deletion test/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
}

// log an error than contains a value that should be redacted
clog.Error(clogs.NewLogError("seeds", "", "contains sesame seeds"))
clog.Error(&clogs.LogError{Code: "seeds", Message: "contains sesame seeds"})

Check warning on line 63 in test/handler.go

View check run for this annotation

Codecov / codecov/patch

test/handler.go#L63

Added line #L63 was not covered by tests

if msg.Text() == "err:config" {
return courier.ErrChannelConfig
Expand Down
5 changes: 0 additions & 5 deletions utils/clogs/clog.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ type LogError struct {
Message string `json:"message"`
}

// NewLogError creates a new log error
func NewLogError(code, extCode, message string, args ...any) *LogError {
return &LogError{Code: code, ExtCode: extCode, Message: fmt.Sprintf(message, args...)}
}

// Redact applies the given redactor to this error
func (e *LogError) Redact(r stringsx.Redactor) *LogError {
return &LogError{Code: e.Code, ExtCode: e.ExtCode, Message: r(e.Message)}
Expand Down
8 changes: 4 additions & 4 deletions utils/clogs/clog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestLogs(t *testing.T) {
require.NoError(t, err)

clog2.HTTP(trace2)
clog2.Error(clogs.NewLogError("", "", "oops"))
clog2.Error(&clogs.LogError{Message: "oops"})
clog2.End()

assert.NotEqual(t, clog1.UUID, clog2.UUID)
Expand All @@ -48,10 +48,10 @@ func TestLogs(t *testing.T) {
require.NoError(t, err)

l1 := clogs.NewLog("test_type1", nil, nil)
l1.Error(clogs.NewLogError("code1", "ext", "message"))
l1.Error(&clogs.LogError{Code: "code1", ExtCode: "ext", Message: "message"})

l2 := clogs.NewLog("test_type2", nil, nil)
l2.Error(clogs.NewLogError("code2", "ext", "message"))
l2.Error(&clogs.LogError{Code: "code2", ExtCode: "ext", Message: "message"})

// write both logs to db
err = ds.PutItem(ctx, "ChannelLogs", l1)
Expand All @@ -65,7 +65,7 @@ func TestLogs(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, l1.UUID, l3.UUID)
assert.Equal(t, clogs.LogType("test_type1"), l3.Type)
assert.Equal(t, []*clogs.LogError{clogs.NewLogError("code1", "ext", "message")}, l3.Errors)
assert.Equal(t, []*clogs.LogError{{Code: "code1", ExtCode: "ext", Message: "message"}}, l3.Errors)
assert.Equal(t, l1.Elapsed, l3.Elapsed)
assert.Equal(t, l1.CreatedOn.Truncate(time.Second), l3.CreatedOn)
}
Loading