forked from digitalocean/godo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request digitalocean#66 from digitalocean/check-faulty-inputs
Add checks for arguments
- Loading branch information
Showing
9 changed files
with
216 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package godo | ||
|
||
import "fmt" | ||
|
||
// ArgError is an error that represents an error with an input to godo. It | ||
// identifies the argument and the cause (if possible). | ||
type ArgError struct { | ||
arg string | ||
reason string | ||
} | ||
|
||
var _ error = &ArgError{} | ||
|
||
// NewArgError creates an InputError. | ||
func NewArgError(arg, reason string) *ArgError { | ||
return &ArgError{ | ||
arg: arg, | ||
reason: reason, | ||
} | ||
} | ||
|
||
func (e *ArgError) Error() string { | ||
return fmt.Sprintf("%s is invalid because %s", e.arg, e.reason) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package godo | ||
|
||
import "testing" | ||
|
||
func TestArgError(t *testing.T) { | ||
expected := "foo is invalid because bar" | ||
err := NewArgError("foo", "bar") | ||
if got := err.Error(); got != expected { | ||
t.Errorf("ArgError().Error() = %q; expected %q", got, expected) | ||
} | ||
} |
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
Oops, something went wrong.