本文整理匯總了Golang中github.com/facebookgo/stackerr.HasUnderlying函數的典型用法代碼示例。如果您正苦於以下問題:Golang HasUnderlying函數的具體用法?Golang HasUnderlying怎麽用?Golang HasUnderlying使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了HasUnderlying函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: configFromDir
func configFromDir(dir string) (config, error) {
l, err := readLegacyConfigFile(filepath.Join(dir, legacyConfigFile))
if err != nil && !stackerr.HasUnderlying(err, stackerr.MatcherFunc(os.IsNotExist)) {
return nil, err
}
if l != nil { // legacy config format
projectConfig := &projectConfig{
Type: legacyParseFormat,
Parse: &parseProjectConfig{
JSSDK: l.Global.ParseVersion,
},
ParserEmail: l.Global.ParserEmail,
}
applications := l.Applications
if applications == nil {
applications = make(map[string]*parseAppConfig)
}
return &parseConfig{
Applications: applications,
projectConfig: projectConfig,
}, nil
}
canonicalize := func(err error) error {
if err == nil {
return nil
}
if stackerr.HasUnderlying(err, stackerr.MatcherFunc(os.IsNotExist)) {
return stackerr.New("Command must be run inside a Parse project.")
}
return err
}
// current config format
p, err := readProjectConfigFile(filepath.Join(dir, parseProject))
if err != nil {
return nil, canonicalize(err)
}
configFile := filepath.Join(dir, parseLocal)
switch p.Type {
case parseFormat:
c, err := readParseConfigFile(configFile)
if err != nil {
return nil, canonicalize(err)
}
if c.Applications == nil {
c.Applications = make(map[string]*parseAppConfig)
}
c.projectConfig = p
return c, nil
}
return nil, stackerr.Newf("Unknown project type: %d.", p.Type)
}
示例2: TestApplyWithExistingRemoveError
func TestApplyWithExistingRemoveError(t *testing.T) {
const image = "x"
givenErr := errors.New("")
container := &Container{
containerConfig: &dockerclient.ContainerConfig{
Image: image,
},
removeExisting: true,
}
client := &mockClient{
inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
return &dockerclient.ContainerInfo{
Id: "y",
Image: "z",
}, nil
},
listImages: func() ([]*dockerclient.Image, error) {
return []*dockerclient.Image{
{
RepoTags: []string{image},
Id: "y",
},
}, nil
},
removeContainer: func(id string, force, volumes bool) error {
return givenErr
},
}
err := container.Apply(client)
ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
示例3: main
func main() {
rx := regexp.MustCompile(os.Args[1])
r := mllp.NewReader(os.Stdin)
w := mllp.NewWriter(os.Stdout)
i := 0
for {
m, err := r.ReadMessage()
if err != nil {
if stackerr.HasUnderlying(err, stackerr.Equals(io.EOF)) {
break
}
panic(err)
}
if rx.Match(m) {
if err := w.WriteMessage(m); err != nil {
panic(err)
}
}
i++
}
}
示例4: TestApplyStartError
func TestApplyStartError(t *testing.T) {
givenErr := errors.New("")
const image = "x"
const id = "y"
container := &Container{
containerConfig: &dockerclient.ContainerConfig{
Image: image,
},
}
client := &mockClient{
inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
return &dockerclient.ContainerInfo{
Id: "a",
Image: id,
Config: &dockerclient.ContainerConfig{},
}, nil
},
listImages: func() ([]*dockerclient.Image, error) {
return []*dockerclient.Image{
{
RepoTags: []string{image},
Id: id,
},
}, nil
},
startContainer: func(id string, config *dockerclient.HostConfig) error {
return givenErr
},
}
err := container.Apply(client)
ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
示例5: TestApplyInitialInspectError
func TestApplyInitialInspectError(t *testing.T) {
givenErr := errors.New("")
container := &Container{
containerConfig: &dockerclient.ContainerConfig{
Image: "x",
},
}
client := &mockClient{
inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
return nil, givenErr
},
}
err := container.Apply(client)
ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
示例6: TestApplyGraphApplyError
func TestApplyGraphApplyError(t *testing.T) {
givenErr := errors.New("")
containers := []*Container{
{
name: "n1",
containerConfig: &dockerclient.ContainerConfig{Image: "in1"},
},
}
client := &mockClient{
inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
return nil, givenErr
},
}
err := ApplyGraph(client, containers)
ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
示例7: TestApplyInspectAfterCreateError
func TestApplyInspectAfterCreateError(t *testing.T) {
container, err := NewContainer(
ContainerName("x"),
ContainerConfig(&dockerclient.ContainerConfig{Image: "foo"}),
)
ensure.Nil(t, err)
client := &mockClient{
inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
return nil, dockerclient.ErrNotFound
},
createContainer: func(config *dockerclient.ContainerConfig, name string) (string, error) {
return "baz", nil
},
}
err = container.Apply(client)
ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(dockerclient.ErrNotFound)))
}
示例8: TestCheckExistingImageIdentifyError
func TestCheckExistingImageIdentifyError(t *testing.T) {
givenErr := errors.New("")
const image = "x"
container := &Container{
containerConfig: &dockerclient.ContainerConfig{
Image: image,
},
}
client := &mockClient{
listImages: func() ([]*dockerclient.Image, error) {
return nil, givenErr
},
}
ok, err := container.checkExisting(client, &dockerclient.ContainerInfo{Image: "z"})
ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
ensure.False(t, ok)
}
示例9: PrettyPrintApps
func (c *HerokuConfig) PrettyPrintApps(e *Env) {
apps := c.Applications
defaultApp := c.GetDefaultApp()
var appNames []string
for appName := range apps {
appNames = append(appNames, appName)
}
sort.Strings(appNames)
if len(appNames) == 0 {
return
}
fmt.Fprintln(
e.Out,
"The following apps are associated with cloud code in the current directory:",
)
for _, appName := range appNames {
if appName == DefaultKey {
continue
}
if defaultApp == appName {
fmt.Fprint(e.Out, "* ")
} else {
fmt.Fprint(e.Out, " ")
}
fmt.Fprintf(e.Out, "%s", appName)
config, _ := apps[appName]
if config.GetLink() != "" {
fmt.Fprintf(e.Out, " -> %s", config.GetLink())
}
herokuAppName, err := FetchHerokuAppName(config.HerokuAppID, e)
if err != nil {
if stackerr.HasUnderlying(err, stackerr.MatcherFunc(HerokuAppNotFound)) {
herokuAppName = ""
} else {
herokuAppName = config.HerokuAppID
}
}
fmt.Fprintf(e.Out, " (%q)\n", herokuAppName)
}
}
示例10: authUser
func (l *login) authUser(e *env) error {
_, err := l.authUserWithToken(e)
if err == nil {
return nil
}
// user never created an account key: educate them
if stackerr.HasUnderlying(err, stackerr.MatcherFunc(os.IsNotExist)) {
fmt.Fprintln(
e.Out,
`We've changed the way the CLI works.
To save time logging in, you should create an account key.
`)
}
apps := &apps{}
fmt.Fprintln(
e.Out,
`Type "parse configure accountkey" to create a new account key.
Read more at: https://parse.com/docs/js/guide#command-line-account-keys
Please login to Parse using your email and password.`,
)
for i := 0; i < numRetries; i++ {
err := l.populateCreds(e)
if err != nil {
return err
}
apps.login.credentials = l.credentials
_, err = apps.restFetchApps(e)
if err == nil {
return nil
}
if i == numRetries-1 && err != nil {
return err
}
if err != errAuth {
fmt.Fprintf(e.Err, "Got error: %s", errorString(e, err))
}
fmt.Fprintf(e.Err, "%s\nPlease try again...\n", err)
l.credentials.password = ""
}
return errAuth
}
示例11: TestApplyRemovesExistingWithoutDesiredImageError
func TestApplyRemovesExistingWithoutDesiredImageError(t *testing.T) {
givenErr := errors.New("")
container := &Container{
containerConfig: &dockerclient.ContainerConfig{
Image: "x",
},
}
client := &mockClient{
inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
return &dockerclient.ContainerInfo{Id: "y", Image: "a"}, nil
},
listImages: func() ([]*dockerclient.Image, error) {
return nil, givenErr
},
}
err := container.Apply(client)
ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
示例12: authUserWithToken
func (l *login) authUserWithToken(e *env) (string, error) {
_, tokenCredentials, err := l.getTokenCredentials(e, e.ParserEmail)
if err != nil {
if stackerr.HasUnderlying(err, stackerr.MatcherFunc(accessKeyNotFound)) {
fmt.Fprintln(e.Err, errorString(e, err))
}
return "", err
}
email, err := l.authToken(e, tokenCredentials.token)
if err != nil {
fmt.Fprintf(e.Err, "Account key could not be used.\nError: %s\n\n", errorString(e, err))
return "", err
}
l.credentials = *tokenCredentials
return email, nil
}
示例13: TestApplyForceRemoveExistingError
func TestApplyForceRemoveExistingError(t *testing.T) {
container, err := NewContainer(
ContainerName("x"),
ContainerConfig(&dockerclient.ContainerConfig{Image: "foo"}),
ContainerForceRemoveExisting(),
)
ensure.Nil(t, err)
givenErr := errors.New("")
client := &mockClient{
removeContainer: func(id string, force, volumes bool) error {
return givenErr
},
inspectContainer: func(name string) (*dockerclient.ContainerInfo, error) {
return &dockerclient.ContainerInfo{Id: "x"}, nil
},
}
err = container.Apply(client)
ensure.True(t, stackerr.HasUnderlying(err, stackerr.Equals(givenErr)))
}
示例14: AuthUser
func (l *Login) AuthUser(e *Env, strict bool) error {
_, err := l.AuthUserWithToken(e, strict)
if err == nil {
return nil
}
if strict {
return err
}
if !stackerr.HasUnderlying(err, stackerr.MatcherFunc(accountKeyNotConfigured)) {
fmt.Fprintln(
e.Out,
`Type "parse configure accountkey" to create a new account key.
Read more at: https://parse.com/docs/cloudcode/guide#command-line-account-keys
Please login to Parse using your email and password.`,
)
}
apps := &Apps{}
for i := 0; i < numRetries; i++ {
err := l.populateCreds(e)
if err != nil {
return err
}
apps.Login.Credentials = l.Credentials
_, err = apps.RestFetchApps(e)
if err == nil {
return nil
}
if i == numRetries-1 && err != nil {
return err
}
if err != errAuth {
fmt.Fprintf(e.Err, "Got error: %s", ErrorString(e, err))
}
fmt.Fprintf(e.Err, "%s\nPlease try again...\n", err)
l.Credentials.Password = ""
}
return errAuth
}
示例15: herokuAppNames
func (h *herokuLink) herokuAppNames(ids []string, e *parsecli.Env) (nameIDs, []string, error) {
var wg errgroup.Group
wg.Add(len(ids))
maxParallel := make(chan struct{}, maxRequests)
var (
ret nameIDs
deletedLinks []string
retMutex sync.Mutex
deletedLinksMutex sync.Mutex
)
getAppName := func(id string) {
defer func() {
wg.Done()
<-maxParallel
}()
appName, err := parsecli.FetchHerokuAppName(id, e)
if err != nil {
if stackerr.HasUnderlying(err, stackerr.MatcherFunc(parsecli.HerokuAppNotFound)) {
deletedLinksMutex.Lock()
defer deletedLinksMutex.Unlock()
deletedLinks = append(deletedLinks, id)
return
}
wg.Error(err) // ignore error if corresponding heroku app was deleted
return
}
retMutex.Lock()
defer retMutex.Unlock()
ret = append(ret, nameID{id: id, name: appName})
}
for _, id := range ids {
go getAppName(id)
}
err := wg.Wait()
sort.Sort(ret)
return ret, deletedLinks, stackerr.Wrap(err)
}