Skip to content
New issue

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

Fix InvalidRemoteErr panic #2728

Merged
merged 4 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions private/buf/cmd/buf/command/mod/modprune/modprune.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ func run(
}
var dependencyModulePins []bufmoduleref.ModulePin
if len(requestReferences) > 0 {
var remote string
var (
remote string
moduleIdentityString string
)
if config.ModuleIdentity != nil && config.ModuleIdentity.Remote() != "" {
remote = config.ModuleIdentity.Remote()
moduleIdentityString = config.ModuleIdentity.IdentityString()
} else {
// At this point we know there's at least one dependency. If it's an unnamed module, select
// the right remote from the list of dependencies.
Expand All @@ -104,10 +108,11 @@ func run(
return fmt.Errorf(`File %q has invalid "deps" references`, existingConfigFilePath)
}
remote = selectedRef.Remote()
moduleIdentityString = selectedRef.IdentityString()
container.Logger().Debug(fmt.Sprintf(
`File %q does not specify the "name" field. Based on the dependency %q, it appears that you are using a BSR instance at %q. Did you mean to specify "name: %s/..." within %q?`,
existingConfigFilePath,
selectedRef.IdentityString(),
moduleIdentityString,
remote,
remote,
existingConfigFilePath,
Expand All @@ -125,8 +130,8 @@ func run(
}),
)
if err != nil {
if remote != bufconnect.DefaultRemote {
return bufcli.NewInvalidRemoteError(err, remote, config.ModuleIdentity.IdentityString())
if !connect.IsWireError(err) && remote != bufconnect.DefaultRemote {
return bufcli.NewInvalidRemoteError(err, remote, moduleIdentityString)
}
return err
}
Expand Down
13 changes: 9 additions & 4 deletions private/buf/cmd/buf/command/mod/modupdate/modupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,13 @@ func getDependencies(
if len(moduleConfig.Build.DependencyModuleReferences) == 0 {
return nil, nil
}
var remote string
var (
remote string
moduleIdentityString string
)
if moduleConfig.ModuleIdentity != nil && moduleConfig.ModuleIdentity.Remote() != "" {
remote = moduleConfig.ModuleIdentity.Remote()
moduleIdentityString = moduleConfig.ModuleIdentity.IdentityString()
} else {
// At this point we know there's at least one dependency. If it's an unnamed module, select
// the right remote from the list of dependencies.
Expand All @@ -226,10 +230,11 @@ func getDependencies(
return nil, fmt.Errorf(`File %q has invalid "deps" references`, existingConfigFilePath)
}
remote = selectedRef.Remote()
moduleIdentityString = selectedRef.IdentityString()
container.Logger().Debug(fmt.Sprintf(
`File %q does not specify the "name" field. Based on the dependency %q, it appears that you are using a BSR instance at %q. Did you mean to specify "name: %s/..." within %q?`,
existingConfigFilePath,
selectedRef.IdentityString(),
moduleIdentityString,
remote,
remote,
existingConfigFilePath,
Expand Down Expand Up @@ -268,8 +273,8 @@ func getDependencies(
}),
)
if err != nil {
if remote != bufconnect.DefaultRemote {
return nil, bufcli.NewInvalidRemoteError(err, remote, moduleConfig.ModuleIdentity.IdentityString())
if !connect.IsWireError(err) && remote != bufconnect.DefaultRemote {
return nil, bufcli.NewInvalidRemoteError(err, remote, moduleIdentityString)
}
return nil, err
}
Expand Down
Loading