diff --git a/command/password.go b/command/password.go index 8bd81dc2..32c85a7a 100644 --- a/command/password.go +++ b/command/password.go @@ -95,7 +95,10 @@ func runPasswordChange(username, pass string) { newPass["NewPassword"] = pass _, err, emessages := force.ChangePassword(id, newPass) if err != nil { - ErrorAndExit(err.Error(), emessages[0].ErrorCode) + if len(emessages) > 0 { + ErrorAndExit(err.Error(), emessages[0].ErrorCode) + } + ErrorAndExit(err.Error()) } else { fmt.Println("\nPassword changed\n ") } diff --git a/command/record.go b/command/record.go index 558a1322..8bc5a2eb 100644 --- a/command/record.go +++ b/command/record.go @@ -174,7 +174,10 @@ func runRecordCreate(object string, fields []string) { attrs := parseArgumentAttrs(fields) id, err, emessages := force.CreateRecord(object, attrs) if err != nil { - ErrorAndExit("Failed to create record: %s (%s)", err.Error(), emessages[0].ErrorCode) + if len(emessages) > 0 { + ErrorAndExit("Failed to create record: %s (%s)", err.Error(), emessages[0].ErrorCode) + } + ErrorAndExit("Failed to create record: %s", err.Error()) } fmt.Printf("Record created: %s\n", id) } diff --git a/command/record_test.go b/command/record_test.go new file mode 100644 index 00000000..f9a3b3c3 --- /dev/null +++ b/command/record_test.go @@ -0,0 +1,58 @@ +package command + +import ( + "testing" +) + +func TestParseArgumentAttrs(t *testing.T) { + tests := []struct { + name string + input []string + expected map[string]string + }{ + { + name: "parses_single_field", + input: []string{"Name:Acme"}, + expected: map[string]string{"Name": "Acme"}, + }, + { + name: "parses_multiple_fields", + input: []string{"Name:Acme", "Industry:Technology"}, + expected: map[string]string{"Name": "Acme", "Industry": "Technology"}, + }, + { + name: "handles_empty_input", + input: []string{}, + expected: map[string]string{}, + }, + { + name: "handles_value_with_colons", + input: []string{"Description:Value:with:colons"}, + expected: map[string]string{"Description": "Value:with:colons"}, + }, + { + name: "handles_empty_value", + input: []string{"Name:"}, + expected: map[string]string{"Name": ""}, + }, + { + name: "handles_quoted_value_with_spaces", + input: []string{"Name:Acme Corp"}, + expected: map[string]string{"Name": "Acme Corp"}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := parseArgumentAttrs(tt.input) + if len(result) != len(tt.expected) { + t.Errorf("Expected %d fields, got %d", len(tt.expected), len(result)) + } + for key, expectedValue := range tt.expected { + if result[key] != expectedValue { + t.Errorf("Expected %s=%q, got %s=%q", key, expectedValue, key, result[key]) + } + } + }) + } +}