Skip to content

Commit

Permalink
Fix most linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredoconnell committed Oct 5, 2023
1 parent 9a9a2d0 commit 3d9cc63
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 140 deletions.
17 changes: 9 additions & 8 deletions atp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (c *client) Execute(
return c.getResult(stepData, cborReader)
}

// handleStepComplete is the deferred function that will handle closing of the received channel
// handleStepComplete is the deferred function that will handle closing of the received channel.
func (c *client) handleStepComplete(runID string, receivedSignals chan schema.Input) {
if receivedSignals != nil {
c.logger.Infof("Closing signal channel for finished step")
Expand Down Expand Up @@ -270,7 +270,7 @@ func (c *client) executeWriteLoop(
if err := c.sendCBOR(RuntimeMessage{
MessageTypeSignal,
signal.RunID,
signalMessage{
SignalMessage{
SignalID: signal.ID,
Data: signal.InputData,
}}); err != nil {
Expand Down Expand Up @@ -315,11 +315,12 @@ func (c *client) sendExecutionResult(runID string, result ExecutionResult) {

func (c *client) sendErrorToAll(err error) {
result := NewErrorExecutionResult(err)
for runID, _ := range c.runningStepResultChannels {
for runID := range c.runningStepResultChannels {
c.sendExecutionResult(runID, result)
}
}

//nolint:funlen
func (c *client) executeReadLoop(cborReader *cbor.Decoder) {
defer func() {
c.mutex.Lock()
Expand All @@ -339,15 +340,15 @@ func (c *client) executeReadLoop(cborReader *cbor.Decoder) {
}
switch runtimeMessage.MessageID {
case MessageTypeWorkDone:
var doneMessage workDoneMessage
var doneMessage WorkDoneMessage
if err := cbor.Unmarshal(runtimeMessage.RawMessageData, &doneMessage); err != nil {
c.logger.Errorf("Failed to decode work done message (%v) for run ID %s ", err, runtimeMessage.RunID)
c.sendExecutionResult(runtimeMessage.RunID, NewErrorExecutionResult(
fmt.Errorf("failed to decode work done message (%w)", err)))
}
c.sendExecutionResult(runtimeMessage.RunID, c.processWorkDone(runtimeMessage.RunID, doneMessage))
case MessageTypeSignal:
var signalMessage signalMessage
var signalMessage SignalMessage
if err := cbor.Unmarshal(runtimeMessage.RawMessageData, &signalMessage); err != nil {
c.logger.Errorf("ATP client for run ID '%s' failed to decode signal message: %v",
runtimeMessage.RunID, err)
Expand All @@ -364,7 +365,7 @@ func (c *client) executeReadLoop(cborReader *cbor.Decoder) {
signalChannel <- signalMessage.ToInput(runtimeMessage.RunID)
}
case MessageTypeError:
var errMessage errorMessage
var errMessage ErrorMessage
if err := cbor.Unmarshal(runtimeMessage.RawMessageData, &errMessage); err != nil {
c.logger.Errorf("Step with run ID '%s' failed to decode error message: %v",
runtimeMessage.RunID, err)
Expand Down Expand Up @@ -409,7 +410,7 @@ func (c *client) getResultV1(
cborReader *cbor.Decoder,
stepData schema.Input,
) ExecutionResult {
var doneMessage workDoneMessage
var doneMessage WorkDoneMessage
if err := cborReader.Decode(&doneMessage); err != nil {
c.logger.Errorf("Failed to read or decode work done message: (%w) for step %s", err, stepData.ID)
return NewErrorExecutionResult(
Expand Down Expand Up @@ -473,7 +474,7 @@ func (c *client) getResultV2(

func (c *client) processWorkDone(
runID string,
doneMessage workDoneMessage,
doneMessage WorkDoneMessage,
) ExecutionResult {
c.logger.Debugf("Step with run ID '%s' completed with output ID '%s'.", runID, doneMessage.OutputID)

Expand Down
10 changes: 5 additions & 5 deletions atp/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,32 @@ type DecodedRuntimeMessage struct {
RawMessageData cbor.RawMessage `cbor:"data"`
}

type workDoneMessage struct {
type WorkDoneMessage struct {
StepID string `cbor:"step_id"`
OutputID string `cbor:"output_id"`
OutputData any `cbor:"output_data"`
DebugLogs string `cbor:"debug_logs"`
}

type signalMessage struct {
type SignalMessage struct {
SignalID string `cbor:"signal_id"`
Data any `cbor:"data"`
}

func (s signalMessage) ToInput(runID string) schema.Input {
func (s SignalMessage) ToInput(runID string) schema.Input {
return schema.Input{RunID: runID, ID: s.SignalID, InputData: s.Data}
}

type clientDoneMessage struct {
// Empty for now.
}

type errorMessage struct {
type ErrorMessage struct {
Error string `cbor:"error"`
StepFatal bool `cbor:"step_fatal"`
ServerFatal bool `cbor:"server_fatal"`
}

func (e errorMessage) ToString(runID string) string {
func (e ErrorMessage) ToString(runID string) string {
return fmt.Sprintf("RunID: %s, err: %s, step fatal: %t, server fatal: %t", runID, e.Error, e.StepFatal, e.ServerFatal)
}
1 change: 1 addition & 0 deletions atp/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ func TestProtocol_Error_Server_WorkStart(t *testing.T) {
time.Sleep(time.Millisecond * 2)
}

//nolint:funlen
func TestProtocol_Error_Client_WorkStart(t *testing.T) {
// Induce error on client's (and server incidentally)
// start work message by closing the client's cbor
Expand Down
Loading

0 comments on commit 3d9cc63

Please sign in to comment.