We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Given the following section of code in the GetAst method:
GetAst
if err != nil { return nil, fmt.Errorf("could not parse filter:%w", err) } else if err := astNode.checkValid(); err != nil { return nil, fmt.Errorf("error validating filter:%w", err) } else { return astNode, nil }
It returns an error using fmt.Errorf. This makes it hard to determine the type of error (either parsing or validation error).
fmt.Errorf
If it were replaced with specific error types, we could handle these errors in the calling functions.
For example:
type ParsingErr struct { err error } func (pe ParsingErr) Error() string { return pe.err.Error() } type ValidationErr struct { err error } func (ve ValidationErr) Error() string { return ve.err.Error() } func CouldNotParse(err error) ParsingErr { return ParsingErr{ err: fmt.Errorf("could not parse filter: %w", err), } } func CouldNotValidate(err error) ValidationErr { return ValidationErr{ err: fmt.Errorf("error validating filter:%w", err), } }
And then the caller could use something like
ast, err = epsearchastv3.GetAst(ast) switch { case errors.As(err, &epsearchastv3.ParsingErr{}): // Handle validation err case err != nil: // handle other err }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Given the following section of code in the
GetAst
method:It returns an error using
fmt.Errorf
. This makes it hard to determine the type of error (either parsing or validation error).If it were replaced with specific error types, we could handle these errors in the calling functions.
For example:
And then the caller could use something like
The text was updated successfully, but these errors were encountered: