errors

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package errors contains the error structures that can occur during command line argument parsing.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadFieldType

type BadFieldType struct {
	Option string
	Field  string
	Type   reflect.Type
}

BadFieldType is the error which indicates that a type of a field of the option store is neither a boolean, a number, a string, nor an array of numbers or strings.

func (BadFieldType) Error

func (e BadFieldType) Error() string

Error is the method to retrieve the message of this error.

Example
package main

import (
	"fmt"
	"reflect"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.BadFieldType{
		Option: "foo-bar",
		Field:  "FooBar",
		Type:   reflect.TypeOf(int(0)),
	}

	fmt.Printf("%s\n", e.Error())
}
Output:

BadFieldType{Option:foo-bar,Field:FooBar,Type:int}

type ConfigHasDefaultsButHasNoArg

type ConfigHasDefaultsButHasNoArg struct {
	StoreKey string
	Name     string
}

ConfigHasDefaultsButHasNoArg is the error which indicates that an option configuration contradicts that the option has default value (.Defaults != nil) but must have no option argument (.HasArg = false).

func (ConfigHasDefaultsButHasNoArg) Error

Error is the method to retrieve the message of this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.ConfigHasDefaultsButHasNoArg{
		StoreKey: "FooBar",
		Name:     "foo-bar",
	}

	fmt.Printf("%s\n", e.Error())
}
Output:

ConfigHasDefaultsButHasNoArg{StoreKey:FooBar,Name:foo-bar}

func (ConfigHasDefaultsButHasNoArg) GetOption

func (e ConfigHasDefaultsButHasNoArg) GetOption() string

GetOption is the method to retrieve the first name of the option in the option configuration that caused this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.ConfigHasDefaultsButHasNoArg{
		StoreKey: "FooBar",
		Name:     "foo-bar",
	}
	var ee errors.InvalidOption = e

	fmt.Printf("%s\n", e.GetOption())
	fmt.Printf("%s\n", ee.GetOption())
}
Output:

foo-bar
foo-bar

type ConfigIsArrayButHasNoArg

type ConfigIsArrayButHasNoArg struct {
	StoreKey string
	Name     string
}

ConfigIsArrayButHasNoArg is the error which indicates that an option configuration contradicts that the option must be an array (.IsArray = true) but must have no option argument (.HasArg = false).

func (ConfigIsArrayButHasNoArg) Error

func (e ConfigIsArrayButHasNoArg) Error() string

Error is the method to retrieve the message of this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.ConfigIsArrayButHasNoArg{
		StoreKey: "FooBar",
		Name:     "foo-bar",
	}

	fmt.Printf("%s\n", e.Error())
}
Output:

ConfigIsArrayButHasNoArg{StoreKey:FooBar,Name:foo-bar}

func (ConfigIsArrayButHasNoArg) GetOption

func (e ConfigIsArrayButHasNoArg) GetOption() string

GetOption is the method to retrieve the first name of the option in the option configuration that caused this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.ConfigIsArrayButHasNoArg{
		StoreKey: "FooBar",
		Name:     "foo-bar",
	}
	var ee errors.InvalidOption = e

	fmt.Printf("%s\n", e.GetOption())
	fmt.Printf("%s\n", ee.GetOption())
}
Output:

foo-bar
foo-bar

type InvalidOption

type InvalidOption interface {
	GetOption() string
	Error() string
}

InvalidOption is the error interface which provides method declarations to retrieve an option that caused this error and an error message.

type OptionArgIsInvalid

type OptionArgIsInvalid struct {
	StoreKey string
	Option   string
	OptArg   string
	TypeKind reflect.Kind
	Cause    error
}

OptionArgIsInvalid is the error which indicates that the option argument is invalidated by the validator in the option configuration.

func (OptionArgIsInvalid) Error

func (e OptionArgIsInvalid) Error() string

Error is the method to retrieve the message of this error.

Example
package main

import (
	"fmt"
	"reflect"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.OptionArgIsInvalid{
		StoreKey: "FooBar",
		Option:   "foo-bar",
		OptArg:   "123",
		TypeKind: reflect.Int,
		Cause:    fmt.Errorf("Bad number format"),
	}

	fmt.Printf("%s\n", e.Error())
}
Output:

OptionArgIsInvalid{StoreKey:FooBar,Option:foo-bar,OptArg:123,TypeKind:int,Cause:Bad number format}

func (OptionArgIsInvalid) GetOption

func (e OptionArgIsInvalid) GetOption() string

GetOption is the method to retrieve the first name of the option in the option configuration that caused this error.

Example
package main

import (
	"fmt"
	"reflect"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.OptionArgIsInvalid{
		StoreKey: "FooBar",
		Option:   "foo-bar",
		OptArg:   "123",
		TypeKind: reflect.Int,
		Cause:    fmt.Errorf("Bad number format"),
	}
	var ee errors.InvalidOption = e

	fmt.Printf("%s\n", e.GetOption())
	fmt.Printf("%s\n", ee.GetOption())
}
Output:

foo-bar
foo-bar

func (OptionArgIsInvalid) Unwrap

func (e OptionArgIsInvalid) Unwrap() error

Unwrap is the method to get an error which is wrapped in this error.

Example
package main

import (
	goerrors "errors"
	"fmt"
	"reflect"

	"github.com/sttk/cliargs/errors"
)

func main() {
	// import ( goerrors "errors" )

	e0 := fmt.Errorf("Bad number format")

	e := errors.OptionArgIsInvalid{
		StoreKey: "FooBar",
		Option:   "foo-bar",
		OptArg:   "123",
		TypeKind: reflect.Int,
		Cause:    e0,
	}

	fmt.Printf("%t\n", goerrors.Is(e, e0))
}
Output:

true

type OptionContainsInvalidChar added in v0.9.0

type OptionContainsInvalidChar struct {
	Option string
}

OptionContainsInvalidChar is the error which indicates that an invalid character is found in the option.

func (OptionContainsInvalidChar) Error added in v0.9.0

Error is the method to retrieve the message of this error.

func (OptionContainsInvalidChar) GetOption added in v0.9.0

func (e OptionContainsInvalidChar) GetOption() string

GetOption is the method to retrieve the name of the option that caused this error.

type OptionIsNotArray

type OptionIsNotArray struct {
	Option   string
	StoreKey string
}

OptionIsNotArray is the error which indicates that an option is input with an option argument multiple times though its option configuration specifies the option is not an array (.IsArray = false).

func (OptionIsNotArray) Error

func (e OptionIsNotArray) Error() string

Error is the method to retrieve the message of this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.OptionIsNotArray{
		Option:   "foo-bar",
		StoreKey: "FooBar",
	}

	fmt.Printf("%s\n", e.Error())
}
Output:

OptionIsNotArray{Option:foo-bar,StoreKey:FooBar}

func (OptionIsNotArray) GetOption

func (e OptionIsNotArray) GetOption() string

GetOption is the method to retrieve the name of the option that caused this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.OptionIsNotArray{
		Option:   "foo-bar",
		StoreKey: "FooBar",
	}
	var ee errors.InvalidOption = e

	fmt.Printf("%s\n", e.GetOption())
	fmt.Printf("%s\n", ee.GetOption())
}
Output:

foo-bar
foo-bar

type OptionNameIsDuplicated

type OptionNameIsDuplicated struct {
	StoreKey string
	Name     string
}

OptionNameIsDuplicated is the error which indicates that an option argument is invalidated by the validator in the option configuration.

func (OptionNameIsDuplicated) Error

func (e OptionNameIsDuplicated) Error() string

Error is the method to retrieve the message of this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.OptionNameIsDuplicated{
		StoreKey: "FooBar",
		Name:     "foo-bar",
	}

	fmt.Printf("%s\n", e.Error())
}
Output:

OptionNameIsDuplicated{StoreKey:FooBar,Name:foo-bar}

func (OptionNameIsDuplicated) GetOption

func (e OptionNameIsDuplicated) GetOption() string

GetOption is the method to retrieve the first name of the option in the option configuration that caused this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.OptionNameIsDuplicated{
		StoreKey: "FooBar",
		Name:     "foo-bar",
	}

	var ee errors.InvalidOption = e

	fmt.Printf("%s\n", e.GetOption())
	fmt.Printf("%s\n", ee.GetOption())
}
Output:

foo-bar
foo-bar

type OptionNeedsArg

type OptionNeedsArg struct {
	Option   string
	StoreKey string
}

OptionNeedsArg is the error which indicates that an option is input with no option argument though its option configuration requires option argument (.HasArg = true).

func (OptionNeedsArg) Error

func (e OptionNeedsArg) Error() string

Error is the method to retrieve the message of this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.OptionNeedsArg{
		StoreKey: "FooBar",
		Option:   "foo-bar",
	}

	fmt.Printf("%s\n", e.Error())
}
Output:

OptionNeedsArg{Option:foo-bar,StoreKey:FooBar}

func (OptionNeedsArg) GetOption

func (e OptionNeedsArg) GetOption() string

GetOption is the method to retrieve the name of the option that caused this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.OptionNeedsArg{
		Option:   "foo-bar",
		StoreKey: "FooBar",
	}

	var ee errors.InvalidOption = e

	fmt.Printf("%s\n", e.GetOption())
	fmt.Printf("%s\n", ee.GetOption())
}
Output:

foo-bar
foo-bar

type OptionStoreIsNotChangeable

type OptionStoreIsNotChangeable struct{}

OptionStoreIsNotChangeable is the error which indicates that the argument of ParseFor method, which is set options produced by parsing command line arguments, is not a pointer.

func (OptionStoreIsNotChangeable) Error

Error is the method to retrieve the message of this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.OptionStoreIsNotChangeable{}

	fmt.Printf("%s\n", e.Error())
}
Output:

OptionStoreIsNotChangeable{}

type OptionTakesNoArg

type OptionTakesNoArg struct {
	Option   string
	StoreKey string
}

OptionTakesNoArg is the error which indicates that an option is input with an option argument though its option configuration does not accept option arguments (.HasArg = false).

func (OptionTakesNoArg) Error

func (e OptionTakesNoArg) Error() string

Error is the method to retrieve the message of this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.OptionTakesNoArg{
		Option:   "foo-bar",
		StoreKey: "FooBar",
	}

	fmt.Printf("%s\n", e.Error())
}
Output:

OptionTakesNoArg{Option:foo-bar,StoreKey:FooBar}

func (OptionTakesNoArg) GetOption

func (e OptionTakesNoArg) GetOption() string

GetOption is the method to retrieve the name of the option that caused this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.OptionTakesNoArg{
		Option:   "foo-bar",
		StoreKey: "FooBar",
	}

	var ee errors.InvalidOption = e

	fmt.Printf("%s\n", e.GetOption())
	fmt.Printf("%s\n", ee.GetOption())
}
Output:

foo-bar
foo-bar

type StoreKeyIsDuplicated

type StoreKeyIsDuplicated struct {
	StoreKey string
	Name     string
}

StoreKeyIsDuplicated is the error which indicates that a store key in an option configuration is duplicated another among all option configurations.

func (StoreKeyIsDuplicated) Error

func (e StoreKeyIsDuplicated) Error() string

Error is the method to retrieve the message of this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.StoreKeyIsDuplicated{
		StoreKey: "FooBar",
		Name:     "foo-bar",
	}

	fmt.Printf("%s\n", e.Error())
}
Output:

StoreKeyIsDuplicated{StoreKey:FooBar,Name:foo-bar}

func (StoreKeyIsDuplicated) GetOption

func (e StoreKeyIsDuplicated) GetOption() string

GetOption is the method to retrieve the first name of the option in the option configuration that caused this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.StoreKeyIsDuplicated{
		StoreKey: "FooBar",
		Name:     "foo-bar",
	}

	var ee errors.InvalidOption = e

	fmt.Printf("%s\n", e.GetOption())
	fmt.Printf("%s\n", ee.GetOption())
}
Output:

foo-bar
foo-bar

type UnconfiguredOption

type UnconfiguredOption struct {
	Option string
}

UnconfiguredOption is the error which indicates that there is no configuration about the input option.

func (UnconfiguredOption) Error

func (e UnconfiguredOption) Error() string

Error is the method to retrieve the message of this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.UnconfiguredOption{
		Option: "foo-bar",
	}

	fmt.Printf("%s\n", e.Error())
}
Output:

UnconfiguredOption{Option:foo-bar}

func (UnconfiguredOption) GetOption

func (e UnconfiguredOption) GetOption() string

GetOption is the method to retrieve the name of the option that caused this error.

Example
package main

import (
	"fmt"

	"github.com/sttk/cliargs/errors"
)

func main() {
	e := errors.UnconfiguredOption{
		Option: "foo-bar",
	}

	var ee errors.InvalidOption = e

	fmt.Printf("%s\n", e.GetOption())
	fmt.Printf("%s\n", ee.GetOption())
}
Output:

foo-bar
foo-bar

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL