Skip to content

Commit

Permalink
Not found lists handling
Browse files Browse the repository at this point in the history
  • Loading branch information
koltyakov committed Feb 26, 2023
1 parent 286c4c7 commit 7e9f7c3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"bin/": true,
".vscode/": true,
"**/*.log": true,
"**/*.db": true,
"**/.cq/": true,
"**/db.sql": true,
"**/.cq/": true
},
"editor.formatOnSave": true,
"editor.minimap.enabled": false
Expand Down
23 changes: 23 additions & 0 deletions client/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package client

import (
"errors"
"strings"
)

// IsNotFound unwraps API response errors checking for 404 Not Found
func IsNotFound(err error) bool {
if err == nil {
return false
}
for {
if err.Error() == "404 Not Found" || strings.Contains(err.Error(), "System.IO.FileNotFoundException") {
return true
}
if err = errors.Unwrap(err); err == nil {
break
}
}

return false
}
8 changes: 8 additions & 0 deletions client/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ func (c *Client) getListInfo(listURI string) (*listInfo, error) {
func (c *Client) tableFromList(listURI string, spec ListSpec) (*schema.Table, *ListModel, error) {
listInfo, err := c.getListInfo(listURI)
if err != nil {
// ToDo: Decide which design is better to warn and go next or fail a sync
// Will stay with a fast fail strateg for now so a user will know about an error immediately
// Otherwise the only way to know about an error is to check `cloudquery.log` for
// `2023-02-26T15:24:36Z ERR list not found, skipping list={ListURI} module=sharepoint-src`
if IsNotFound(err) { // List not found, warn and skip
c.Logger.Error().Str("list", listURI).Msg("list not found")
return nil, nil, fmt.Errorf("list not found \"%s\": %w", listURI, err)
}
return nil, nil, err
}

Expand Down

0 comments on commit 7e9f7c3

Please sign in to comment.