Error handling fixes (#1816)

Signed-off-by: Denis O <denis.o@linux.com>
This commit is contained in:
Denis O 2024-07-15 10:58:43 +01:00 committed by GitHub
parent f668c48ffd
commit 864aa9d1d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 8 additions and 40 deletions

View File

@ -230,9 +230,6 @@ func (c *RemoteClient) writeLockInfo(info *statemgr.LockInfo) error {
if err != nil {
return err
}
if err != nil {
return err
}
if info == nil {
delete(blob.MetaData, lockInfoMetaKey)

View File

@ -1034,18 +1034,18 @@ func (m *MockProjects) Update(ctx context.Context, projectID string, options tfe
}
func (m *MockProjects) Delete(ctx context.Context, projectID string) error {
var p *tfe.Project = nil
var projectToDelete *tfe.Project
for _, p := range m.projects {
if p.ID == projectID {
projectToDelete = p
break
}
}
if p == nil {
if projectToDelete == nil {
return tfe.ErrResourceNotFound
}
delete(m.projects, p.Name)
delete(m.projects, projectToDelete.Name)
return nil
}

View File

@ -55,7 +55,7 @@ func (c GRPCCloudClient) Execute(args []string, stdout, stderr io.Writer) int {
return 1
}
} else if bytes := response.GetStderr(); len(bytes) > 0 {
fmt.Fprint(stderr, string(bytes))
_, err := fmt.Fprint(stderr, string(bytes))
if err != nil {
log.Printf("[ERROR] Failed to write cloudplugin output to stderr: %s", err)
return 1

View File

@ -69,9 +69,6 @@ func (c *StateMeta) State(enc encryption.Encryption) (statemgr.Full, error) {
}
localB := localRaw.(*backendLocal.Local)
_, stateOutPath, _ = localB.StatePaths(workspace)
if err != nil {
return nil, err
}
realState = s
}

View File

@ -79,11 +79,6 @@ func (c *WorkspaceSelectCommand) Run(args []string) int {
return 1
}
if err != nil {
c.Ui.Error(fmt.Sprintf("Failed to load backend: %s", err))
return 1
}
// This command will not write state
c.ignoreRemoteVersionConflict(b)

View File

@ -718,7 +718,7 @@ func scpUploadDirProtocol(name string, w io.Writer, r *bufio.Reader, f func() er
return err
}
fmt.Fprintln(w, "E")
_, err = fmt.Fprintln(w, "E")
if err != nil {
return err
}

View File

@ -114,7 +114,7 @@ func (s *Schema) coreConfigSchemaAttribute() *configschema.Attribute {
// "Required" to false and let the provider try calling its
// DefaultFunc again during the validate step, where it can then
// return the error.
if err != nil || (err == nil && v != nil) {
if err != nil || v != nil {
reqd = false
opt = true
}

View File

@ -18,7 +18,6 @@ func TestGraphDot(t *testing.T) {
Graph testGraphFunc
Opts dag.DotOpts
Expect string
Error string
}{
{
Name: "empty",
@ -236,23 +235,7 @@ digraph {
tn := tc.Name
t.Run(tn, func(t *testing.T) {
g := tc.Graph()
var err error
//actual, err := GraphDot(g, &tc.Opts)
actual := string(g.Dot(&tc.Opts))
if err == nil && tc.Error != "" {
t.Fatalf("%s: expected err: %s, got none", tn, tc.Error)
}
if err != nil && tc.Error == "" {
t.Fatalf("%s: unexpected err: %s", tn, err)
}
if err != nil && tc.Error != "" {
if !strings.Contains(err.Error(), tc.Error) {
t.Fatalf("%s: expected err: %s\nto contain: %s", tn, err, tc.Error)
}
return
}
expected := strings.TrimSpace(tc.Expect) + "\n"
if actual != expected {
t.Fatalf("%s:\n\nexpected:\n%s\n\ngot:\n%s", tn, expected, actual)

View File

@ -326,11 +326,7 @@ func (n *NodeAbstractResourceInstance) writeResourceInstanceStateImpl(ctx EvalCo
return nil
}
if obj != nil {
log.Printf("[TRACE] %s: writing state object for %s", logFuncName, absAddr)
} else {
log.Printf("[TRACE] %s: removing state object for %s", logFuncName, absAddr)
}
schema, currentVersion := providerSchema.SchemaForResourceAddr(absAddr.ContainingResource().Resource)
if schema == nil {