-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
service: update error types to make them more logicless, simplify val…
…idations. closes #350, related with #348, a part of #337 * error types now doesn't call methods from its struct fields for validation. * remove isValid and Validate methods from types and adapt generic service.ValidateParametersSchema() method. * TestValidParameters removed from service package. no longer needed.
- Loading branch information
Showing
10 changed files
with
218 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,88 @@ | ||
package service | ||
|
||
// EventNotFoundError is an error when an event cannot be found in a service. | ||
import "fmt" | ||
|
||
// EventNotFoundError is an error returned when corresponding event cannot be found in service. | ||
type EventNotFoundError struct { | ||
Service *Service | ||
EventKey string | ||
EventKey string | ||
ServiceName string | ||
} | ||
|
||
func (e *EventNotFoundError) Error() string { | ||
return "Event '" + e.EventKey + "' not found in service '" + e.Service.Name + "'" | ||
return fmt.Sprintf("Event %q not found in service %q", e.EventKey, e.ServiceName) | ||
} | ||
|
||
// InvalidEventDataError is an error when the data of an event are not valid. | ||
type InvalidEventDataError struct { | ||
Event *Event | ||
EventKey string | ||
EventData map[string]interface{} | ||
// TaskNotFoundError is an error returned when corresponding task cannot be found in service. | ||
type TaskNotFoundError struct { | ||
TaskKey string | ||
ServiceName string | ||
} | ||
|
||
func (e *InvalidEventDataError) Error() string { | ||
errorString := "Data of event '" + e.EventKey + "' is invalid" | ||
for _, warning := range e.Event.Validate(e.EventData) { | ||
errorString = errorString + ". " + warning.String() | ||
} | ||
return errorString | ||
func (e *TaskNotFoundError) Error() string { | ||
return fmt.Sprintf("Task %q not found in service %q", e.TaskKey, e.ServiceName) | ||
} | ||
|
||
// TaskNotFoundError is an error when a task cannot be found in a service. | ||
type TaskNotFoundError struct { | ||
Service *Service | ||
TaskKey string | ||
// TaskInputNotFoundError is an error returned when service doesn't contain corresponding input. | ||
type TaskInputNotFoundError struct { | ||
TaskKey string | ||
TaskInputKey string | ||
ServiceName string | ||
} | ||
|
||
func (e *TaskNotFoundError) Error() string { | ||
return "Task '" + e.TaskKey + "' not found in service '" + e.Service.Name + "'" | ||
func (e *TaskInputNotFoundError) Error() string { | ||
return fmt.Sprintf("Input %q of task %q not found in service %q", e.TaskInputKey, e.TaskKey, e.ServiceName) | ||
} | ||
|
||
// InvalidTaskInputError is an error when the inputs of a task are not valid. | ||
type InvalidTaskInputError struct { | ||
Task *Task | ||
TaskKey string | ||
InputData map[string]interface{} | ||
// TaskOutputNotFoundError is an error returned when service doesn't contain corresponding output. | ||
type TaskOutputNotFoundError struct { | ||
TaskKey string | ||
TaskOutputKey string | ||
ServiceName string | ||
} | ||
|
||
func (e *InvalidTaskInputError) Error() string { | ||
errorString := "Inputs of task '" + e.TaskKey + "' are invalid" | ||
for _, warning := range e.Task.Validate(e.InputData) { | ||
errorString = errorString + ". " + warning.String() | ||
} | ||
return errorString | ||
func (e *TaskOutputNotFoundError) Error() string { | ||
return fmt.Sprintf("Output %q of task %q not found in service %q", e.TaskOutputKey, e.TaskKey, e.ServiceName) | ||
} | ||
|
||
// InputNotFoundError is an error when a service doesn't contains a specific input. | ||
type InputNotFoundError struct { | ||
Service *Service | ||
TaskKey string | ||
InputKey string | ||
// InvalidEventDataError is an error returned when the data of corresponding event is not valid. | ||
type InvalidEventDataError struct { | ||
EventKey string | ||
Warnings []*ParameterWarning | ||
} | ||
|
||
func (e *InputNotFoundError) Error() string { | ||
return "Input '" + e.InputKey + "' of task '" + e.TaskKey + "' not found in service '" + e.Service.Name + "'" | ||
func (e *InvalidEventDataError) Error() string { | ||
s := fmt.Sprintf("Data of event %q is invalid", e.EventKey) | ||
for _, warning := range e.Warnings { | ||
s = fmt.Sprintf("%s. %s", s, warning) | ||
} | ||
return s | ||
} | ||
|
||
// OutputNotFoundError is an error when a service doesn't contain a specific output. | ||
type OutputNotFoundError struct { | ||
Service *Service | ||
TaskKey string | ||
OutputKey string | ||
// InvalidTaskInputError is an error returned when the inputs of corresponding task are not valid. | ||
type InvalidTaskInputError struct { | ||
TaskKey string | ||
Warnings []*ParameterWarning | ||
} | ||
|
||
func (e *OutputNotFoundError) Error() string { | ||
return "Output '" + e.OutputKey + "' of task '" + e.TaskKey + "' not found in service '" + e.Service.Name + "'" | ||
func (e *InvalidTaskInputError) Error() string { | ||
s := fmt.Sprintf("Inputs of task %q are invalid", e.TaskKey) | ||
for _, warning := range e.Warnings { | ||
s = fmt.Sprintf("%s. %s", s, warning) | ||
} | ||
return s | ||
} | ||
|
||
// InvalidOutputDataError is an error when the outputs for one task result are not valid. | ||
type InvalidOutputDataError struct { | ||
Output *Output | ||
TaskKey string | ||
OutputKey string | ||
OutputData map[string]interface{} | ||
// InvalidTaskOutputError is an error returned when the outputs of corresponding task are not valid. | ||
type InvalidTaskOutputError struct { | ||
TaskKey string | ||
TaskOutputKey string | ||
Warnings []*ParameterWarning | ||
} | ||
|
||
func (e *InvalidOutputDataError) Error() string { | ||
errorString := "Outputs '" + e.OutputKey + "' of task '" + e.TaskKey + "' are invalid" | ||
for _, warning := range e.Output.Validate(e.OutputData) { | ||
errorString = errorString + ". " + warning.String() | ||
func (e *InvalidTaskOutputError) Error() string { | ||
s := fmt.Sprintf("Outputs %q of task %q are invalid", e.TaskOutputKey, e.TaskKey) | ||
for _, warning := range e.Warnings { | ||
s = fmt.Sprintf("%s. %s", s, warning) | ||
} | ||
return errorString | ||
return s | ||
} |
Oops, something went wrong.