Skip to content

Commit

Permalink
Improve Grammar, Capitalization, and Punctuation in MeshKit Errors
Browse files Browse the repository at this point in the history
Signed-off-by: weilirs <weilirs@umich.edu>
  • Loading branch information
weilirs committed Feb 12, 2025
1 parent c99eaae commit 9ecc508
Show file tree
Hide file tree
Showing 17 changed files with 463 additions and 89 deletions.
30 changes: 25 additions & 5 deletions broker/nats/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,37 @@ const (
)

func ErrConnect(err error) error {
return errors.New(ErrConnectCode, errors.Alert, []string{"Connection to broker failed"}, []string{err.Error()}, []string{"Endpoint might not be reachable"}, []string{"Make sure the NATS endpoint is reachable"})
return errors.New(ErrConnectCode, errors.Alert,
[]string{"Connection to broker failed."},
[]string{err.Error()},
[]string{"Endpoint might not be reachable."},
[]string{"Make sure the NATS endpoint is reachable."})
}
func ErrEncodedConn(err error) error {
return errors.New(ErrEncodedConnCode, errors.Alert, []string{"Encoding connection failed with broker"}, []string{err.Error()}, []string{"Endpoint might not be reachable"}, []string{"Make sure the NATS endpoint is reachable"})
return errors.New(ErrEncodedConnCode, errors.Alert,
[]string{"Encoding connection failed with broker."},
[]string{err.Error()},
[]string{"Endpoint might not be reachable."},
[]string{"Make sure the NATS endpoint is reachable."})
}
func ErrPublish(err error) error {
return errors.New(ErrPublishCode, errors.Alert, []string{"Publish failed"}, []string{err.Error()}, []string{"NATS is unhealthy"}, []string{"Make sure NATS is up and running"})
return errors.New(ErrPublishCode, errors.Alert,
[]string{"Publish failed."},
[]string{err.Error()},
[]string{"NATS is unhealthy."},
[]string{"Make sure NATS is up and running."})
}
func ErrPublishRequest(err error) error {
return errors.New(ErrPublishRequestCode, errors.Alert, []string{"Publish request failed"}, []string{err.Error()}, []string{"NATS is unhealthy"}, []string{"Make sure NATS is up and running"})
return errors.New(ErrPublishRequestCode, errors.Alert,
[]string{"Publish request failed."},
[]string{err.Error()},
[]string{"NATS is unhealthy."},
[]string{"Make sure NATS is up and running."})
}
func ErrQueueSubscribe(err error) error {
return errors.New(ErrQueueSubscribeCode, errors.Alert, []string{"Subscription failed"}, []string{err.Error()}, []string{"NATS is unhealthy"}, []string{"Make sure NATS is up and running"})
return errors.New(ErrQueueSubscribeCode, errors.Alert,
[]string{"Subscription failed."},
[]string{err.Error()},
[]string{"NATS is unhealthy."},
[]string{"Make sure NATS is up and running."})
}
42 changes: 35 additions & 7 deletions encoding/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,57 @@ const (

// ErrDecodeYaml is the error when the yaml unmarshal fails
func ErrDecodeYaml(err error) error {
return errors.New(ErrDecodeYamlCode, errors.Alert, []string{"Error occurred while decoding YAML"}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid YAML object"})
return errors.New(ErrDecodeYamlCode, errors.Alert,
[]string{"Error occurred while decoding YAML."},
[]string{err.Error()},
[]string{"Invalid YAML format or structure."},
[]string{"Please verify the YAML syntax and structure is correct."})
}

func ErrUnmarshal(err error) error {
return errors.New(ErrUnmarshalCode, errors.Alert, []string{"Unmarshal unknown error: "}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
return errors.New(ErrUnmarshalCode, errors.Alert,
[]string{"Unknown error occurred during unmarshaling."},
[]string{err.Error()},
[]string{"The data format may be invalid or corrupted."},
[]string{"Please verify the data format matches the expected schema."})
}

func ErrUnmarshalInvalid(err error, typ reflect.Type) error {
return errors.New(ErrUnmarshalInvalidCode, errors.Alert, []string{"Unmarshal invalid error for type: ", typ.String()}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
return errors.New(ErrUnmarshalInvalidCode, errors.Alert,
[]string{"Invalid unmarshal error for type: " + typ.String() + "."},
[]string{err.Error()},
[]string{"The data structure does not match the expected type."},
[]string{"Please ensure the data structure matches the " + typ.String() + " type definition."})
}

func ErrUnmarshalSyntax(err error, offset int64) error {
return errors.New(ErrUnmarshalSyntaxCode, errors.Alert, []string{"Unmarshal syntax error at offest: ", strconv.Itoa(int(offset))}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
return errors.New(ErrUnmarshalSyntaxCode, errors.Alert,
[]string{"Syntax error detected during unmarshal at offset: " + strconv.Itoa(int(offset)) + "."},
[]string{err.Error()},
[]string{"The data contains invalid syntax or formatting."},
[]string{"Please check the syntax at or near position " + strconv.Itoa(int(offset)) + "."})
}

func ErrUnmarshalType(err error, value string) error {
return errors.New(ErrUnmarshalTypeCode, errors.Alert, []string{"Unmarshal type error at key: %s. Error: %s", value}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
return errors.New(ErrUnmarshalTypeCode, errors.Alert,
[]string{"Type mismatch error at key: " + value + "."},
[]string{err.Error()},
[]string{"The data type does not match the expected type for this field."},
[]string{"Please ensure the value type matches the schema definition for key: " + value + "."})
}

func ErrUnmarshalUnsupportedType(err error, typ reflect.Type) error {
return errors.New(ErrUnmarshalUnsupportedTypeCode, errors.Alert, []string{"Unmarshal unsupported type error at key: ", typ.String()}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
return errors.New(ErrUnmarshalUnsupportedTypeCode, errors.Alert,
[]string{"Unsupported type encountered: " + typ.String() + "."},
[]string{err.Error()},
[]string{"The data contains a type that cannot be unmarshaled."},
[]string{"Please use only supported data types in your input."})
}

func ErrUnmarshalUnsupportedValue(err error, value reflect.Value) error {
return errors.New(ErrUnmarshalUnsupportedValueCode, errors.Alert, []string{"Unmarshal unsupported value error at key: ", value.String()}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
return errors.New(ErrUnmarshalUnsupportedValueCode, errors.Alert,
[]string{"Unsupported value encountered: " + value.String() + "."},
[]string{err.Error()},
[]string{"The data contains a value that cannot be unmarshaled."},
[]string{"Please use only supported values in your input."})
}
6 changes: 5 additions & 1 deletion generators/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ var (
)

func ErrUnsupportedRegistrant(err error) error {
return errors.New(ErrUnsupportedRegistrantCode, errors.Alert, []string{"unsupported registrant"}, []string{err.Error()}, []string{"Select from one of the supported registrants"}, []string{"Check docs for the list of supported registrants"})
return errors.New(ErrUnsupportedRegistrantCode, errors.Alert,
[]string{"Unsupported registrant."},
[]string{err.Error()},
[]string{"The selected registrant is not supported by Meshery."},
[]string{"Please check the documentation for the list of supported registrants."})
}
21 changes: 19 additions & 2 deletions generators/github/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,26 @@ const (
)

func ErrGenerateGitHubPackage(err error, pkgName string) error {
return errors.New(ErrGenerateGitHubPackageCode, errors.Alert, []string{fmt.Sprintf("error generate package for %s", pkgName)}, []string{err.Error()}, []string{"invalid sourceurl provided", "repository might be private"}, []string{"provided sourceURL according to the format", "provide approparite credentials to clone a private repository"})
return errors.New(ErrGenerateGitHubPackageCode, errors.Alert,
[]string{fmt.Sprintf("Error generating package for %s.", pkgName)},
[]string{err.Error()},
[]string{
"Invalid source URL provided.",
"Repository might be private.",
},
[]string{
"Provide source URL according to the format.",
"Provide appropriate credentials to clone a private repository.",
})
}

func ErrInvalidGitHubSourceURL(err error) error {
return errors.New(ErrInvalidGitHubSourceURLCode, errors.Alert, []string{}, []string{err.Error()}, []string{"sourceURL provided might be invalid", "provided repo/version tag does not exist"}, []string{"ensure source url follows the format: git://<owner>/<repositoryname>/<branch>/<version>/<path from the root of repository>"})
return errors.New(ErrInvalidGitHubSourceURLCode, errors.Alert,
[]string{"Invalid GitHub source URL."},
[]string{err.Error()},
[]string{
"Source URL provided might be invalid.",
"Provided repository/version tag does not exist.",
},
[]string{"Ensure source URL follows the format: git://<owner>/<repositoryname>/<branch>/<version>/<path from the root of repository>."})
}
21 changes: 18 additions & 3 deletions models/controllers/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,28 @@ var (
)

func ErrGetControllerStatus(err error) error {
return errors.New(ErrGetControllerStatusCode, errors.Alert, []string{"Error getting the status of the meshery controller"}, []string{err.Error()}, []string{"Controller may not be healthy or not deployed"}, []string{"Make sure the controller is deployed and healthy"})
return errors.New(ErrGetControllerStatusCode, errors.Alert,
[]string{"Error getting the status of the Meshery controller."},
[]string{err.Error()},
[]string{"Controller may not be healthy or not deployed."},
[]string{"Make sure the controller is deployed and healthy."})
}

func ErrDeployController(err error) error {
return errors.New(ErrDeployControllerCode, errors.Alert, []string{"Error deploying Meshery Operator"}, []string{err.Error()}, []string{"Meshery Server could not connect to the Kubernetes cluster. Meshery Operator was not deployed", "Insufficient file permission to read kubeconfig"}, []string{"Verify that the available kubeconfig is accessible by Meshery Server - verify sufficient file permissions (only needs read permission)"})
return errors.New(ErrDeployControllerCode, errors.Alert,
[]string{"Error deploying Meshery Operator."},
[]string{err.Error()},
[]string{
"Meshery Server could not connect to the Kubernetes cluster. Meshery Operator was not deployed.",
"Insufficient file permissions to read kubeconfig.",
},
[]string{"Verify that the available kubeconfig is accessible by Meshery Server - verify sufficient file permissions (only needs read permission)."})
}

func ErrGetControllerPublicEndpoint(err error) error {
return errors.New(ErrGetControllerPublicEndpointCode, errors.Alert, []string{"Could not get the public endpoint of the controller"}, []string{err.Error()}, []string{"Client configuration may not be valid"}, []string{"Make sure the client configuration is valid"})
return errors.New(ErrGetControllerPublicEndpointCode, errors.Alert,
[]string{"Could not get the public endpoint of the controller."},
[]string{err.Error()},
[]string{"Client configuration may not be valid."},
[]string{"Make sure the client configuration is valid."})
}
6 changes: 5 additions & 1 deletion models/converter/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ const (
)

func ErrUnknownFormat(format DesignFormat) error {
return errors.New(ErrUnknownFormatCode, errors.Alert, []string{fmt.Sprintf("\"%s\" format is not supported", format)}, []string{fmt.Sprintf("Failed to export design in \"%s\" format", format)}, []string{"The format is not supported by the current version of Meshery server"}, []string{"Make sure to export design in one of the supported format"})
return errors.New(ErrUnknownFormatCode, errors.Alert,
[]string{fmt.Sprintf("The '%s' format is not supported.", format)},
[]string{fmt.Sprintf("Failed to export design in '%s' format.", format)},
[]string{"The format is not supported by the current version of Meshery server."},
[]string{"Please export the design in one of the supported formats."})
}
16 changes: 14 additions & 2 deletions models/meshmodel/core/policies/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ const (
)

func ErrPrepareForEval(err error) error {
return errors.New(ErrPrepareForEvalCode, errors.Alert, []string{"error preparing for evaluation"}, []string{err.Error()}, []string{"query might be empty", "rego store provided without associated transaction", "uncommitted transaction"}, []string{"please provide the transaction for the loaded store"})
return errors.New(ErrPrepareForEvalCode, errors.Alert,
[]string{"Error preparing for evaluation."},
[]string{err.Error()},
[]string{
"Query might be empty.",
"Rego store provided without associated transaction.",
"Uncommitted transaction.",
},
[]string{"Please provide the transaction for the loaded store."})
}

func ErrEval(err error) error {
return errors.New(ErrEvalCode, errors.Alert, []string{"error evaluating policy for the given input"}, []string{err.Error()}, []string{"The policy query is invalid, see: https://github.com/open-policy-agent/opa/blob/main/rego/resultset.go (Allowed func)"}, []string{"please provide a valid non-empty query"})
return errors.New(ErrEvalCode, errors.Alert,
[]string{"Error evaluating policy for the given input."},
[]string{err.Error()},
[]string{"The policy query is invalid. See: https://github.com/open-policy-agent/opa/blob/main/rego/resultset.go (Allowed func)."},
[]string{"Please provide a valid non-empty query."})
}
6 changes: 5 additions & 1 deletion models/meshmodel/core/v1beta1/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ const (
)

func ErrUnknownKind(err error) error {
return errors.New(ErrUnknownKindCode, errors.Alert, []string{"unsupported connection kind detected"}, []string{err.Error()}, []string{"The component's registrant is not supported by the version of server you are running"}, []string{"Try upgrading to latest available version"})
return errors.New(ErrUnknownKindCode, errors.Alert,
[]string{"Unsupported connection kind detected."},
[]string{err.Error()},
[]string{"The component's registrant is not supported by the version of server you are running."},
[]string{"Try upgrading to the latest available version."})
}
6 changes: 5 additions & 1 deletion models/meshmodel/entity/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ const (
)

func ErrUpdateEntityStatus(err error, entity string, status EntityStatus) error {
return errors.New(ErrUpdateEntityStatusCode, errors.Alert, []string{fmt.Sprintf("unable to update %s to %s", entity, status)}, []string{err.Error()}, []string{}, []string{})
return errors.New(ErrUpdateEntityStatusCode, errors.Alert,
[]string{fmt.Sprintf("Unable to update %s to %s.", entity, status)},
[]string{err.Error()},
[]string{"Entity status update failed due to internal error."},
[]string{"Please try again. If the issue persists, check the entity and status values."})
}
Loading

0 comments on commit 9ecc508

Please sign in to comment.