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

Add configurable error level handling and custom loggers #20

Merged
merged 8 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
wip
  • Loading branch information
tbonfort committed May 28, 2021
commit a0f4ab04b7582b556cd8d5254f962876ba17f490
22 changes: 19 additions & 3 deletions doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,22 +517,38 @@ func Example_vectorTutorial() {
// created geometry { "type": "Point", "coordinates": [ 1.0, 1.0 ] }
}

//ExampleErrorHandler_sentinel is an example to make godal.Open return a specific golang
//error when the gdal emitted error/log matches certain criteria
func ExampleErrorHandler_sentinel() {
sentinel := errors.New("noent")
eh := func(ec godal.ErrorCategory, code int, msg string) error {
/* do some advanced checking of ec, code and msg to determine if this is an actual error */
not_an_error := false
if not_an_error {
haveError := true
if !haveError {
log.Println(msg)
return nil
}
return sentinel

}
_, err := godal.Open("nonexistent.tif", godal.ErrLogger(eh))
if err == sentinel {
fmt.Println(err.Error())
}

// Output:
// noent
}

//ExampleErrorHandler_warnings is an example to set up an error handler that ignores gdal warnings
func ExampleErrorHandler_warnings() {
eh := func(ec godal.ErrorCategory, code int, msg string) error {
if ec <= godal.CE_Warning {
log.Println(msg)
return nil
}
return fmt.Errorf("GDAL %d: %s", code, msg)
}
_, err := godal.Open("nonexistent.tif", godal.ErrLogger(eh))
// err if returned will not arise from a gdal warning
_ = err
}
Loading