Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tbonfort committed May 28, 2021
1 parent 4a5f1eb commit a0f4ab0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1,274 deletions.
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

0 comments on commit a0f4ab0

Please sign in to comment.