Skip to content

Commit

Permalink
feat: use a minimal airtable record in case the whole one generates a…
Browse files Browse the repository at this point in the history
…n error
  • Loading branch information
moul committed Oct 7, 2018
1 parent d8d3dcf commit d4b732c
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions cmd_airtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,21 @@ func airtableSync(opts *airtableOptions) error {
continue
}
logger().Debug("creating airtable record without slices", zap.String("URL", issue.URL))
r := issue.ToAirtableRecord()
r.Fields = airtableIssue{
URL: r.Fields.URL,
r := minimalAirtableRecord{
Fields: minimalAirtableIssue{
URL: issue.URL,
Errors: "initialization",
},
}
if err := table.Create(&r); err != nil {
return err
}
records = append(records, r)
records = append(records, airtableRecord{
ID: r.ID,
Fields: airtableIssue{
URL: issue.URL,
},
})
}

// update/destroy existing ones
Expand All @@ -125,8 +132,11 @@ func airtableSync(opts *airtableOptions) error {
record.Fields = issue.ToAirtableRecord().Fields
if err := table.Update(&record); err != nil {
logger().Warn("failed to update record, retrying without slices", zap.String("URL", issue.URL), zap.Error(err))
record.Fields = airtableIssue{
URL: record.Fields.URL,
record := minimalAirtableRecord{
ID: record.ID,
Fields: minimalAirtableIssue{
URL: issue.URL,
},
}
if typedErr, ok := err.(airtable.ErrClientRequest); ok {
record.Fields.Errors = typedErr.Err.Error()
Expand All @@ -148,6 +158,11 @@ type airtableRecord struct {
Fields airtableIssue `json:"fields,omitempty"`
}

type minimalAirtableRecord struct {
ID string `json:"id,omitempty"`
Fields minimalAirtableIssue `json:"fields,omitempty"`
}

func (ai airtableIssue) String() string {
out, _ := json.Marshal(ai)
return string(out)
Expand Down Expand Up @@ -201,6 +216,11 @@ type airtableIssue struct {
Errors string
}

type minimalAirtableIssue struct {
URL string
Errors string
}

func (ai airtableIssue) Equals(other airtableIssue) bool {
sameSlice := func(a, b []string) bool {
if a == nil {
Expand Down

0 comments on commit d4b732c

Please sign in to comment.